Browse Source

Switch to efficient algorithm

adaptive-webui-19844
Chocobo1 1 year ago
parent
commit
d6adebe4c0
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 7
      src/base/bittorrent/torrentimpl.cpp
  2. 9
      src/base/net/downloadmanager.cpp
  3. 2
      src/base/preferences.cpp

7
src/base/bittorrent/torrentimpl.cpp

@ -31,7 +31,6 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <type_traits>
#include <libtorrent/address.hpp> #include <libtorrent/address.hpp>
#include <libtorrent/alert_types.hpp> #include <libtorrent/alert_types.hpp>
@ -551,8 +550,7 @@ QVector<TrackerEntry> TorrentImpl::trackers() const
void TorrentImpl::addTrackers(QVector<TrackerEntry> trackers) void TorrentImpl::addTrackers(QVector<TrackerEntry> trackers)
{ {
// TODO: use std::erase_if() in C++20 trackers.removeIf([](const TrackerEntry &entry) { return entry.url.isEmpty(); });
trackers.erase(std::remove_if(trackers.begin(), trackers.end(), [](const TrackerEntry &entry) { return entry.url.isEmpty(); }), trackers.end());
const auto newTrackers = QSet<TrackerEntry>(trackers.cbegin(), trackers.cend()) const auto newTrackers = QSet<TrackerEntry>(trackers.cbegin(), trackers.cend())
- QSet<TrackerEntry>(m_trackerEntries.cbegin(), m_trackerEntries.cend()); - QSet<TrackerEntry>(m_trackerEntries.cbegin(), m_trackerEntries.cend());
@ -596,8 +594,7 @@ void TorrentImpl::removeTrackers(const QStringList &trackers)
void TorrentImpl::replaceTrackers(QVector<TrackerEntry> trackers) void TorrentImpl::replaceTrackers(QVector<TrackerEntry> trackers)
{ {
// TODO: use std::erase_if() in C++20 trackers.removeIf([](const TrackerEntry &entry) { return entry.url.isEmpty(); });
trackers.erase(std::remove_if(trackers.begin(), trackers.end(), [](const TrackerEntry &entry) { return entry.url.isEmpty(); }), trackers.end());
std::sort(trackers.begin(), trackers.end() std::sort(trackers.begin(), trackers.end()
, [](const TrackerEntry &lhs, const TrackerEntry &rhs) { return lhs.tier < rhs.tier; }); , [](const TrackerEntry &lhs, const TrackerEntry &rhs) { return lhs.tier < rhs.tier; });

9
src/base/net/downloadmanager.cpp

@ -42,7 +42,6 @@
#include <QSslError> #include <QSslError>
#include <QUrl> #include <QUrl>
#include "base/algorithm.h"
#include "base/global.h" #include "base/global.h"
#include "base/logger.h" #include "base/logger.h"
#include "base/preferences.h" #include "base/preferences.h"
@ -63,7 +62,7 @@ public:
{ {
const QDateTime now = QDateTime::currentDateTime(); const QDateTime now = QDateTime::currentDateTime();
QList<QNetworkCookie> cookies = Preferences::instance()->getNetworkCookies(); QList<QNetworkCookie> cookies = Preferences::instance()->getNetworkCookies();
Algorithm::removeIf(cookies, [&now](const QNetworkCookie &cookie) cookies.removeIf([&now](const QNetworkCookie &cookie)
{ {
return cookie.isSessionCookie() || (cookie.expirationDate() <= now); return cookie.isSessionCookie() || (cookie.expirationDate() <= now);
}); });
@ -75,7 +74,7 @@ public:
{ {
const QDateTime now = QDateTime::currentDateTime(); const QDateTime now = QDateTime::currentDateTime();
QList<QNetworkCookie> cookies = allCookies(); QList<QNetworkCookie> cookies = allCookies();
Algorithm::removeIf(cookies, [&now](const QNetworkCookie &cookie) cookies.removeIf([&now](const QNetworkCookie &cookie)
{ {
return cookie.isSessionCookie() || (cookie.expirationDate() <= now); return cookie.isSessionCookie() || (cookie.expirationDate() <= now);
}); });
@ -90,7 +89,7 @@ public:
{ {
const QDateTime now = QDateTime::currentDateTime(); const QDateTime now = QDateTime::currentDateTime();
QList<QNetworkCookie> cookies = QNetworkCookieJar::cookiesForUrl(url); QList<QNetworkCookie> cookies = QNetworkCookieJar::cookiesForUrl(url);
Algorithm::removeIf(cookies, [&now](const QNetworkCookie &cookie) cookies.removeIf([&now](const QNetworkCookie &cookie)
{ {
return !cookie.isSessionCookie() && (cookie.expirationDate() <= now); return !cookie.isSessionCookie() && (cookie.expirationDate() <= now);
}); });
@ -102,7 +101,7 @@ public:
{ {
const QDateTime now = QDateTime::currentDateTime(); const QDateTime now = QDateTime::currentDateTime();
QList<QNetworkCookie> cookies = cookieList; QList<QNetworkCookie> cookies = cookieList;
Algorithm::removeIf(cookies, [&now](const QNetworkCookie &cookie) cookies.removeIf([&now](const QNetworkCookie &cookie)
{ {
return !cookie.isSessionCookie() && (cookie.expirationDate() <= now); return !cookie.isSessionCookie() && (cookie.expirationDate() <= now);
}); });

2
src/base/preferences.cpp

@ -702,7 +702,7 @@ QVector<Utils::Net::Subnet> Preferences::getWebUiAuthSubnetWhitelist() const
void Preferences::setWebUiAuthSubnetWhitelist(QStringList subnets) void Preferences::setWebUiAuthSubnetWhitelist(QStringList subnets)
{ {
Algorithm::removeIf(subnets, [](const QString &subnet) subnets.removeIf([](const QString &subnet)
{ {
return !Utils::Net::parseSubnet(subnet.trimmed()).has_value(); return !Utils::Net::parseSubnet(subnet.trimmed()).has_value();
}); });

Loading…
Cancel
Save