mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-14 01:03:08 -07:00
Merge pull request #8558 from luis-pereira/containter-anti-pattern
Don't create temporary containers just to iterate over them
This commit is contained in:
commit
a5294e1e08
14 changed files with 120 additions and 61 deletions
|
@ -71,6 +71,7 @@
|
|||
#include <libtorrent/session_status.hpp>
|
||||
#include <libtorrent/torrent_info.hpp>
|
||||
|
||||
#include "base/algorithm.h"
|
||||
#include "base/logger.h"
|
||||
#include "base/net/downloadhandler.h"
|
||||
#include "base/net/downloadmanager.h"
|
||||
|
@ -126,16 +127,16 @@ namespace
|
|||
QStringMap map_cast(const QVariantMap &map)
|
||||
{
|
||||
QStringMap result;
|
||||
foreach (const QString &key, map.keys())
|
||||
result[key] = map.value(key).toString();
|
||||
for (auto i = map.cbegin(); i != map.cend(); ++i)
|
||||
result[i.key()] = i.value().toString();
|
||||
return result;
|
||||
}
|
||||
|
||||
QVariantMap map_cast(const QStringMap &map)
|
||||
{
|
||||
QVariantMap result;
|
||||
foreach (const QString &key, map.keys())
|
||||
result[key] = map.value(key);
|
||||
for (auto i = map.cbegin(); i != map.cend(); ++i)
|
||||
result[i.key()] = i.value();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -197,7 +198,8 @@ namespace
|
|||
{
|
||||
QStringMap expanded = categories;
|
||||
|
||||
foreach (const QString &category, categories.keys()) {
|
||||
for (auto i = categories.cbegin(); i != categories.cend(); ++i) {
|
||||
const QString &category = i.key();
|
||||
foreach (const QString &subcat, Session::expandCategory(category)) {
|
||||
if (!expanded.contains(subcat))
|
||||
expanded[subcat] = "";
|
||||
|
@ -783,14 +785,16 @@ bool Session::removeCategory(const QString &name)
|
|||
bool result = false;
|
||||
if (isSubcategoriesEnabled()) {
|
||||
// remove subcategories
|
||||
QString test = name + "/";
|
||||
foreach (const QString &category, m_categories.keys()) {
|
||||
const QString test = name + "/";
|
||||
Dict::removeIf(m_categories, [this, &test, &result](const QString &category, const QString &)
|
||||
{
|
||||
if (category.startsWith(test)) {
|
||||
m_categories.remove(category);
|
||||
result = true;
|
||||
emit categoryRemoved(category);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
result = (m_categories.remove(name) > 0) || result;
|
||||
|
@ -2001,8 +2005,8 @@ void Session::decreaseTorrentsPriority(const QStringList &hashes)
|
|||
torrentQueue.pop();
|
||||
}
|
||||
|
||||
foreach (const InfoHash &hash, m_loadedMetadata.keys())
|
||||
torrentQueuePositionBottom(m_nativeSession->find_torrent(hash));
|
||||
for (auto i = m_loadedMetadata.cbegin(); i != m_loadedMetadata.cend(); ++i)
|
||||
torrentQueuePositionBottom(m_nativeSession->find_torrent(i.key()));
|
||||
}
|
||||
|
||||
void Session::topTorrentsPriority(const QStringList &hashes)
|
||||
|
@ -2046,8 +2050,8 @@ void Session::bottomTorrentsPriority(const QStringList &hashes)
|
|||
torrentQueue.pop();
|
||||
}
|
||||
|
||||
foreach (const InfoHash &hash, m_loadedMetadata.keys())
|
||||
torrentQueuePositionBottom(m_nativeSession->find_torrent(hash));
|
||||
for (auto i = m_loadedMetadata.cbegin(); i != m_loadedMetadata.cend(); ++i)
|
||||
torrentQueuePositionBottom(m_nativeSession->find_torrent(i.key()));
|
||||
}
|
||||
|
||||
QHash<InfoHash, TorrentHandle *> Session::torrents() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue