mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 13:18:06 -06:00
Utilize algorithms from std::ranges
The result is shorter code and improves readability. Note that `asConst()` is still required for non-const containers, otherwise the container will detach. PR #23342.
This commit is contained in:
@@ -86,7 +86,7 @@ void APIController::requireParams(const QList<QString> &requiredParams) const
|
||||
}
|
||||
|
||||
if (!missingParams.isEmpty())
|
||||
throw APIError(APIErrorType::BadParams, tr("Missing required parameters: %1").arg(missingParams.join(u", "_s)));
|
||||
throw APIError(APIErrorType::BadParams, tr("Missing required parameters: %1").arg(missingParams.join(u", ")));
|
||||
}
|
||||
|
||||
void APIController::setResult(const QString &result)
|
||||
|
||||
@@ -980,7 +980,7 @@ void AppController::setPreferencesAction()
|
||||
const QString ifaceValue {it.value().toString()};
|
||||
|
||||
const QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
|
||||
const auto ifacesIter = std::find_if(ifaces.cbegin(), ifaces.cend(), [&ifaceValue](const QNetworkInterface &iface)
|
||||
const auto ifacesIter = std::ranges::find_if(ifaces, [&ifaceValue](const QNetworkInterface &iface)
|
||||
{
|
||||
return (!iface.addressEntries().isEmpty()) && (iface.name() == ifaceValue);
|
||||
});
|
||||
|
||||
@@ -628,7 +628,7 @@ void TorrentsController::infoAction()
|
||||
return false;
|
||||
};
|
||||
|
||||
std::sort(torrentList.begin(), torrentList.end()
|
||||
std::ranges::sort(torrentList
|
||||
, [reverse, &sortedColumn, &lessThan](const QVariant &torrent1, const QVariant &torrent2)
|
||||
{
|
||||
const QVariant value1 {torrent1.toMap().value(sortedColumn)};
|
||||
@@ -931,8 +931,7 @@ void TorrentsController::filesAction()
|
||||
const int filesCount = torrent->filesCount();
|
||||
const QStringList indexStrings = idxIt.value().split(u'|');
|
||||
fileIndexes.reserve(indexStrings.size());
|
||||
std::transform(indexStrings.cbegin(), indexStrings.cend(), std::back_inserter(fileIndexes)
|
||||
, [&filesCount](const QString &indexString) -> int
|
||||
for (const QString &indexString : indexStrings)
|
||||
{
|
||||
bool ok = false;
|
||||
const int index = indexString.toInt(&ok);
|
||||
@@ -940,8 +939,8 @@ void TorrentsController::filesAction()
|
||||
throw APIError(APIErrorType::Conflict, tr("\"%1\" is not a valid file index.").arg(indexString));
|
||||
if (index >= filesCount)
|
||||
throw APIError(APIErrorType::Conflict, tr("Index %1 is out of bounds.").arg(indexString));
|
||||
return index;
|
||||
});
|
||||
fileIndexes.push_back(index);
|
||||
}
|
||||
}
|
||||
|
||||
QJsonArray fileList = getFiles(torrent, fileIndexes);
|
||||
@@ -1348,7 +1347,7 @@ void TorrentsController::addPeersAction()
|
||||
|
||||
applyToTorrents(hashes, [peers, peerList, &results](BitTorrent::Torrent *const torrent)
|
||||
{
|
||||
const int peersAdded = std::count_if(peerList.cbegin(), peerList.cend(), [torrent](const BitTorrent::PeerAddress &peer)
|
||||
const int peersAdded = std::ranges::count_if(peerList, [torrent](const BitTorrent::PeerAddress &peer)
|
||||
{
|
||||
return torrent->connectPeer(peer);
|
||||
});
|
||||
|
||||
@@ -446,7 +446,8 @@ void WebApplication::configure()
|
||||
m_sessionCookieName = SESSION_COOKIE_NAME_PREFIX + QString::number(pref->getWebUIPort());
|
||||
|
||||
m_domainList = pref->getServerDomains().split(u';', Qt::SkipEmptyParts);
|
||||
std::for_each(m_domainList.begin(), m_domainList.end(), [](QString &entry) { entry = entry.trimmed(); });
|
||||
for (QString &entry : m_domainList)
|
||||
entry = entry.trimmed();
|
||||
|
||||
m_isCSRFProtectionEnabled = pref->isWebUICSRFProtectionEnabled();
|
||||
m_isSecureCookieEnabled = pref->isWebUISecureCookieEnabled();
|
||||
|
||||
Reference in New Issue
Block a user