Convert all foreach() to range-based for()

This commit is contained in:
thalieht
2018-11-18 20:40:37 +02:00
parent d668a4fe6d
commit 6b1d26d555
64 changed files with 326 additions and 292 deletions

View File

@@ -30,6 +30,7 @@
#include <QJsonArray>
#include "base/global.h"
#include "base/logger.h"
#include "base/utils/string.h"
@@ -71,7 +72,7 @@ void LogController::mainAction()
Logger *const logger = Logger::instance();
QVariantList msgList;
foreach (const Log::Msg &msg, logger->getMessages(lastKnownId)) {
for (const Log::Msg &msg : copyAsConst(logger->getMessages(lastKnownId))) {
if (!((msg.type == Log::NORMAL && isNormal)
|| (msg.type == Log::INFO && isInfo)
|| (msg.type == Log::WARNING && isWarning)
@@ -110,7 +111,7 @@ void LogController::peersAction()
Logger *const logger = Logger::instance();
QVariantList peerList;
foreach (const Log::Peer &peer, logger->getPeers(lastKnownId)) {
for (const Log::Peer &peer : copyAsConst(logger->getPeers(lastKnownId))) {
QVariantMap map;
map[KEY_LOG_ID] = peer.id;
map[KEY_LOG_TIMESTAMP] = peer.timestamp;

View File

@@ -263,7 +263,7 @@ void SearchController::checkForUpdatesFinished(const QHash<QString, PluginVersio
LogMsg(tr("Updating %1 plugins").arg(updateInfo.size()), Log::INFO);
SearchPluginManager *const pluginManager = SearchPluginManager::instance();
for (const QString &pluginName : updateInfo.keys()) {
for (const QString &pluginName : copyAsConst(updateInfo.keys())) {
LogMsg(tr("Updating plugin %1").arg(pluginName), Log::INFO);
pluginManager->updatePlugin(pluginName);
}

View File

@@ -35,6 +35,7 @@
#include "base/bittorrent/peerinfo.h"
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/global.h"
#include "base/net/geoipmanager.h"
#include "base/preferences.h"
#include "base/utils/fs.h"
@@ -133,7 +134,7 @@ namespace
// num_peers is not reliable (adds up peers, which didn't even overcome tcp handshake)
quint32 peers = 0;
foreach (BitTorrent::TorrentHandle *const torrent, BitTorrent::Session::instance()->torrents())
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(BitTorrent::Session::instance()->torrents()))
peers += torrent->peersCount();
map[KEY_TRANSFER_WRITE_CACHE_OVERLOAD] = ((sessionStatus.diskWriteQueue > 0) && (peers > 0)) ? Utils::String::fromDouble((100. * sessionStatus.diskWriteQueue) / peers, 2) : "0";
map[KEY_TRANSFER_READ_CACHE_OVERLOAD] = ((sessionStatus.diskReadQueue > 0) && (peers > 0)) ? Utils::String::fromDouble((100. * sessionStatus.diskReadQueue) / peers, 2) : "0";
@@ -268,7 +269,7 @@ namespace
syncData = data;
}
else {
foreach (QVariant item, data) {
for (const QVariant &item : data) {
if (!prevData.contains(item))
// new list item found - append it to syncData
syncData.append(item);
@@ -409,7 +410,7 @@ void SyncController::maindataAction()
BitTorrent::Session *const session = BitTorrent::Session::instance();
foreach (BitTorrent::TorrentHandle *const torrent, session->torrents()) {
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(session->torrents())) {
QVariantMap map = serialize(*torrent);
map.remove(KEY_TORRENT_HASH);
@@ -468,7 +469,7 @@ void SyncController::torrentPeersAction()
QVariantMap data;
QVariantHash peers;
QList<BitTorrent::PeerInfo> peersList = torrent->peers();
const QList<BitTorrent::PeerInfo> peersList = torrent->peers();
#ifndef DISABLE_COUNTRIES_RESOLUTION
bool resolvePeerCountries = Preferences::instance()->resolvePeerCountries();
#else
@@ -477,7 +478,7 @@ void SyncController::torrentPeersAction()
data[KEY_SYNC_TORRENT_PEERS_SHOW_FLAGS] = resolvePeerCountries;
foreach (const BitTorrent::PeerInfo &pi, peersList) {
for (const BitTorrent::PeerInfo &pi : peersList) {
if (pi.address().ip.isNull()) continue;
QVariantMap peer;
#ifndef DISABLE_COUNTRIES_RESOLUTION

View File

@@ -113,7 +113,7 @@ namespace
void applyToTorrents(const QStringList &hashes, const std::function<void (BitTorrent::TorrentHandle *torrent)> &func)
{
if ((hashes.size() == 1) && (hashes[0] == QLatin1String("all"))) {
foreach (BitTorrent::TorrentHandle *torrent, BitTorrent::Session::instance()->torrents())
for (BitTorrent::TorrentHandle *torrent : copyAsConst(BitTorrent::Session::instance()->torrents()))
func(torrent);
}
else {
@@ -167,7 +167,7 @@ void TorrentsController::infoAction()
QVariantList torrentList;
TorrentFilter torrentFilter(filter, (hashSet.isEmpty() ? TorrentFilter::AnyHash : hashSet), category);
foreach (BitTorrent::TorrentHandle *const torrent, BitTorrent::Session::instance()->torrents()) {
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(BitTorrent::Session::instance()->torrents())) {
if (torrentFilter.match(torrent))
torrentList.append(serialize(*torrent));
}
@@ -307,7 +307,7 @@ void TorrentsController::trackersAction()
throw APIError(APIErrorType::NotFound);
QHash<QString, BitTorrent::TrackerInfo> trackersData = torrent->trackerInfos();
foreach (const BitTorrent::TrackerEntry &tracker, torrent->trackers()) {
for (const BitTorrent::TrackerEntry &tracker : copyAsConst(torrent->trackers())) {
QVariantMap trackerDict;
trackerDict[KEY_TRACKER_URL] = tracker.url();
const BitTorrent::TrackerInfo data = trackersData.value(tracker.url());
@@ -346,7 +346,7 @@ void TorrentsController::webseedsAction()
if (!torrent)
throw APIError(APIErrorType::NotFound);
foreach (const QUrl &webseed, torrent->urlSeeds()) {
for (const QUrl &webseed : copyAsConst(torrent->urlSeeds())) {
QVariantMap webSeedDict;
webSeedDict[KEY_WEBSEED_URL] = webseed.toString();
webSeedList.append(webSeedDict);
@@ -419,7 +419,7 @@ void TorrentsController::pieceHashesAction()
const QVector<QByteArray> hashes = torrent->info().pieceHashes();
pieceHashes.reserve(hashes.size());
foreach (const QByteArray &hash, hashes)
for (const QByteArray &hash : hashes)
pieceHashes.append(hash.toHex());
setResult(QJsonArray::fromVariantList(pieceHashes));
@@ -531,7 +531,7 @@ void TorrentsController::addTrackersAction()
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash);
if (torrent) {
QList<BitTorrent::TrackerEntry> trackers;
foreach (QString url, params()["urls"].split('\n')) {
for (QString url : copyAsConst(params()["urls"].split('\n'))) {
url = url.trimmed();
if (!url.isEmpty())
trackers << url;
@@ -575,7 +575,7 @@ void TorrentsController::uploadLimitAction()
const QStringList hashes {params()["hashes"].split('|')};
QVariantMap map;
foreach (const QString &hash, hashes) {
for (const QString &hash : hashes) {
int limit = -1;
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash);
if (torrent)
@@ -592,7 +592,7 @@ void TorrentsController::downloadLimitAction()
const QStringList hashes {params()["hashes"].split('|')};
QVariantMap map;
foreach (const QString &hash, hashes) {
for (const QString &hash : hashes) {
int limit = -1;
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash);
if (torrent)