mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-25 18:56:34 +03:00
Switch to efficient algorithm
This commit is contained in:
parent
c58aa58cba
commit
d6adebe4c0
3 changed files with 7 additions and 11 deletions
|
@ -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; });
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
});
|
});
|
||||||
|
|
|
@ -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…
Reference in a new issue