From e90a2c00a5c72a35bbb19c7da8840836f426d444 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 2 Aug 2019 12:55:06 +0800 Subject: [PATCH 1/2] Replace QList by QVector --- src/base/bittorrent/magneturi.cpp | 3 ++- src/base/bittorrent/magneturi.h | 5 ++-- src/base/bittorrent/peerinfo.h | 5 ++-- src/base/bittorrent/session.cpp | 4 ++-- src/base/bittorrent/session.h | 6 ++--- src/base/bittorrent/torrenthandle.cpp | 27 ++++++++++++---------- src/base/bittorrent/torrenthandle.h | 9 ++++---- src/base/bittorrent/torrentinfo.cpp | 11 ++++++--- src/base/bittorrent/torrentinfo.h | 3 +-- src/base/filesystemwatcher.h | 4 ++-- src/base/preferences.cpp | 14 +++++++---- src/base/preferences.h | 2 +- src/base/search/searchhandler.cpp | 10 +++++--- src/base/search/searchhandler.h | 3 ++- src/base/utils/net.cpp | 2 +- src/base/utils/net.h | 3 ++- src/gui/properties/peerlistwidget.cpp | 4 ++-- src/gui/properties/peersadditiondialog.cpp | 2 +- src/gui/properties/peersadditiondialog.h | 6 ++--- src/gui/properties/propertieswidget.cpp | 12 ++++++---- src/gui/search/pluginselectdialog.cpp | 5 ++-- src/gui/search/pluginselectdialog.h | 2 +- src/gui/search/searchjobwidget.cpp | 2 +- src/gui/search/searchjobwidget.h | 2 +- src/gui/torrentcontentmodel.cpp | 2 +- src/gui/torrentcontentmodelfolder.cpp | 4 ++-- src/gui/torrentcontentmodelfolder.h | 6 ++--- src/gui/torrentcontentmodelitem.h | 4 ++-- src/webui/api/synccontroller.cpp | 3 ++- src/webui/webapplication.h | 2 +- 30 files changed, 94 insertions(+), 73 deletions(-) diff --git a/src/base/bittorrent/magneturi.cpp b/src/base/bittorrent/magneturi.cpp index c098431dd..9cb79e4c0 100644 --- a/src/base/bittorrent/magneturi.cpp +++ b/src/base/bittorrent/magneturi.cpp @@ -80,6 +80,7 @@ MagnetUri::MagnetUri(const QString &source) for (const std::string &tracker : m_addTorrentParams.trackers) m_trackers.append(lt::announce_entry {tracker}); + m_urlSeeds.reserve(m_addTorrentParams.url_seeds.size()); for (const std::string &urlSeed : m_addTorrentParams.url_seeds) m_urlSeeds.append(QUrl(QString::fromStdString(urlSeed))); } @@ -104,7 +105,7 @@ QVector MagnetUri::trackers() const return m_trackers; } -QList MagnetUri::urlSeeds() const +QVector MagnetUri::urlSeeds() const { return m_urlSeeds; } diff --git a/src/base/bittorrent/magneturi.h b/src/base/bittorrent/magneturi.h index dea6d81b1..87cb734f1 100644 --- a/src/base/bittorrent/magneturi.h +++ b/src/base/bittorrent/magneturi.h @@ -31,7 +31,6 @@ #include -#include #include #include @@ -51,7 +50,7 @@ namespace BitTorrent InfoHash hash() const; QString name() const; QVector trackers() const; - QList urlSeeds() const; + QVector urlSeeds() const; QString url() const; lt::add_torrent_params addTorrentParams() const; @@ -62,7 +61,7 @@ namespace BitTorrent InfoHash m_hash; QString m_name; QVector m_trackers; - QList m_urlSeeds; + QVector m_urlSeeds; lt::add_torrent_params m_addTorrentParams; }; } diff --git a/src/base/bittorrent/peerinfo.h b/src/base/bittorrent/peerinfo.h index 9e407a1d5..5ba7b1e3a 100644 --- a/src/base/bittorrent/peerinfo.h +++ b/src/base/bittorrent/peerinfo.h @@ -46,6 +46,7 @@ namespace BitTorrent Q_DECLARE_TR_FUNCTIONS(PeerInfo) public: + PeerInfo() = default; PeerInfo(const TorrentHandle *torrent, const lt::peer_info &nativeInfo); bool fromDHT() const; @@ -98,8 +99,8 @@ namespace BitTorrent void calcRelevance(const TorrentHandle *torrent); void determineFlags(); - lt::peer_info m_nativeInfo; - qreal m_relevance; + lt::peer_info m_nativeInfo = {}; + qreal m_relevance = 0; QString m_flags; QString m_flagsDescription; }; diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 7ba283063..a049eb478 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -3409,14 +3409,14 @@ void Session::handleTorrentTrackersChanged(TorrentHandle *const torrent) emit trackersChanged(torrent); } -void Session::handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QList &newUrlSeeds) +void Session::handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QVector &newUrlSeeds) { torrent->saveResumeData(); for (const QUrl &newUrlSeed : newUrlSeeds) LogMsg(tr("URL seed '%1' was added to torrent '%2'").arg(newUrlSeed.toString(), torrent->name())); } -void Session::handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QList &urlSeeds) +void Session::handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QVector &urlSeeds) { torrent->saveResumeData(); for (const QUrl &urlSeed : urlSeeds) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 3f2031731..8ca0e1db1 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -36,10 +36,10 @@ #include #include -#include #include #include #include +#include #include "base/settingvalue.h" #include "base/types.h" @@ -439,8 +439,8 @@ namespace BitTorrent void handleTorrentTrackersAdded(TorrentHandle *const torrent, const QVector &newTrackers); void handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QVector &deletedTrackers); void handleTorrentTrackersChanged(TorrentHandle *const torrent); - void handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QList &newUrlSeeds); - void handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QList &urlSeeds); + void handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QVector &newUrlSeeds); + void handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QVector &urlSeeds); void handleTorrentResumeDataReady(TorrentHandle *const torrent, const lt::entry &data); void handleTorrentResumeDataFailed(TorrentHandle *const torrent); void handleTorrentTrackerReply(TorrentHandle *const torrent, const QString &trackerUrl); diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 59ef250ba..6d512fa6b 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -475,20 +475,23 @@ void TorrentHandle::replaceTrackers(const QVector &trackers) } } -QList TorrentHandle::urlSeeds() const +QVector TorrentHandle::urlSeeds() const { - QList urlSeeds; const std::set seeds = m_nativeHandle.url_seeds(); + QVector urlSeeds; + urlSeeds.reserve(seeds.size()); + for (const std::string &urlSeed : seeds) urlSeeds.append(QUrl(urlSeed.c_str())); return urlSeeds; } -void TorrentHandle::addUrlSeeds(const QList &urlSeeds) +void TorrentHandle::addUrlSeeds(const QVector &urlSeeds) { - QList addedUrlSeeds; + QVector addedUrlSeeds; + addedUrlSeeds.reserve(urlSeeds.size()); for (const QUrl &urlSeed : urlSeeds) { if (addUrlSeed(urlSeed)) addedUrlSeeds << urlSeed; @@ -498,9 +501,10 @@ void TorrentHandle::addUrlSeeds(const QList &urlSeeds) m_session->handleTorrentUrlSeedsAdded(this, addedUrlSeeds); } -void TorrentHandle::removeUrlSeeds(const QList &urlSeeds) +void TorrentHandle::removeUrlSeeds(const QVector &urlSeeds) { - QList removedUrlSeeds; + QVector removedUrlSeeds; + removedUrlSeeds.reserve(urlSeeds.size()); for (const QUrl &urlSeed : urlSeeds) { if (removeUrlSeed(urlSeed)) removedUrlSeeds << urlSeed; @@ -512,7 +516,7 @@ void TorrentHandle::removeUrlSeeds(const QList &urlSeeds) bool TorrentHandle::addUrlSeed(const QUrl &urlSeed) { - QList seeds = urlSeeds(); + const QVector seeds = urlSeeds(); if (seeds.contains(urlSeed)) return false; m_nativeHandle.add_url_seed(urlSeed.toString().toStdString()); @@ -521,7 +525,7 @@ bool TorrentHandle::addUrlSeed(const QUrl &urlSeed) bool TorrentHandle::removeUrlSeed(const QUrl &urlSeed) { - QList seeds = urlSeeds(); + const QVector seeds = urlSeeds(); if (!seeds.contains(urlSeed)) return false; m_nativeHandle.remove_url_seed(urlSeed.toString().toStdString()); @@ -1170,16 +1174,15 @@ bool TorrentHandle::superSeeding() const #endif } -QList TorrentHandle::peers() const +QVector TorrentHandle::peers() const { - QList peers; std::vector nativePeers; - m_nativeHandle.get_peer_info(nativePeers); + QVector peers; + peers.reserve(nativePeers.size()); for (const lt::peer_info &peer : nativePeers) peers << PeerInfo(this, peer); - return peers; } diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index ef47b597c..77829d559 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -37,7 +37,6 @@ #include #include -#include #include #include #include @@ -263,7 +262,7 @@ namespace BitTorrent int queuePosition() const; QVector trackers() const; QHash trackerInfos() const; - QList urlSeeds() const; + QVector urlSeeds() const; QString error() const; qlonglong totalDownload() const; qlonglong totalUpload() const; @@ -288,7 +287,7 @@ namespace BitTorrent int downloadLimit() const; int uploadLimit() const; bool superSeeding() const; - QList peers() const; + QVector peers() const; QBitArray pieces() const; QBitArray downloadingPieces() const; QVector pieceAvailability() const; @@ -326,8 +325,8 @@ namespace BitTorrent void flushCache(); void addTrackers(const QVector &trackers); void replaceTrackers(const QVector &trackers); - void addUrlSeeds(const QList &urlSeeds); - void removeUrlSeeds(const QList &urlSeeds); + void addUrlSeeds(const QVector &urlSeeds); + void removeUrlSeeds(const QVector &urlSeeds); bool connectPeer(const PeerAddress &peerAddress); QString toMagnetUri() const; diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index 8f938264a..8f128dce2 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -278,14 +278,19 @@ QVector TorrentInfo::trackers() const return ret; } -QList TorrentInfo::urlSeeds() const +QVector TorrentInfo::urlSeeds() const { if (!isValid()) return {}; - QList urlSeeds; - for (const lt::web_seed_entry &webSeed : m_nativeInfo->web_seeds()) + const std::vector &nativeWebSeeds = m_nativeInfo->web_seeds(); + + QVector urlSeeds; + urlSeeds.reserve(nativeWebSeeds.size()); + + for (const lt::web_seed_entry &webSeed : nativeWebSeeds) { if (webSeed.type == lt::web_seed_entry::url_seed) urlSeeds.append(QUrl(webSeed.url.c_str())); + } return urlSeeds; } diff --git a/src/base/bittorrent/torrentinfo.h b/src/base/bittorrent/torrentinfo.h index 3b60560e8..b94461324 100644 --- a/src/base/bittorrent/torrentinfo.h +++ b/src/base/bittorrent/torrentinfo.h @@ -33,7 +33,6 @@ #include #include -#include #include #include "base/indexrange.h" @@ -89,7 +88,7 @@ namespace BitTorrent qlonglong fileSize(int index) const; qlonglong fileOffset(int index) const; QVector trackers() const; - QList urlSeeds() const; + QVector urlSeeds() const; QByteArray metadata() const; QStringList filesForPiece(int pieceIndex) const; QVector fileIndicesForPiece(int pieceIndex) const; diff --git a/src/base/filesystemwatcher.h b/src/base/filesystemwatcher.h index af4c96163..2e733498d 100644 --- a/src/base/filesystemwatcher.h +++ b/src/base/filesystemwatcher.h @@ -32,8 +32,8 @@ #include #include #include -#include #include +#include class QStringList; @@ -67,7 +67,7 @@ private: QHash m_partialTorrents; QTimer m_partialTorrentTimer; - QList m_watchedFolders; + QVector m_watchedFolders; QTimer m_watchTimer; }; diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 0112040f2..29ab6e5e3 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -528,17 +528,21 @@ void Preferences::setWebUiAuthSubnetWhitelistEnabled(const bool enabled) setValue("Preferences/WebUI/AuthSubnetWhitelistEnabled", enabled); } -QList Preferences::getWebUiAuthSubnetWhitelist() const +QVector Preferences::getWebUiAuthSubnetWhitelist() const { - QList subnets; - for (const QString &rawSubnet : asConst(value("Preferences/WebUI/AuthSubnetWhitelist").toStringList())) { + const QStringList subnets = value("Preferences/WebUI/AuthSubnetWhitelist").toStringList(); + + QVector ret; + ret.reserve(subnets.size()); + + for (const QString &rawSubnet : subnets) { bool ok = false; const Utils::Net::Subnet subnet = Utils::Net::parseSubnet(rawSubnet.trimmed(), &ok); if (ok) - subnets.append(subnet); + ret.append(subnet); } - return subnets; + return ret; } void Preferences::setWebUiAuthSubnetWhitelist(QStringList subnets) diff --git a/src/base/preferences.h b/src/base/preferences.h index 18af4907a..14080bb67 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -188,7 +188,7 @@ public: void setWebUiLocalAuthEnabled(bool enabled); bool isWebUiAuthSubnetWhitelistEnabled() const; void setWebUiAuthSubnetWhitelistEnabled(bool enabled); - QList getWebUiAuthSubnetWhitelist() const; + QVector getWebUiAuthSubnetWhitelist() const; void setWebUiAuthSubnetWhitelist(QStringList subnets); QString getWebUiUsername() const; void setWebUiUsername(const QString &username); diff --git a/src/base/search/searchhandler.cpp b/src/base/search/searchhandler.cpp index 1d341cdce..5194c5007 100644 --- a/src/base/search/searchhandler.cpp +++ b/src/base/search/searchhandler.cpp @@ -127,13 +127,16 @@ void SearchHandler::processFinished(const int exitcode) void SearchHandler::readSearchOutput() { QByteArray output = m_searchProcess->readAllStandardOutput(); - output.replace("\r", ""); + output.replace('\r', ""); + QList lines = output.split('\n'); if (!m_searchResultLineTruncated.isEmpty()) lines.prepend(m_searchResultLineTruncated + lines.takeFirst()); m_searchResultLineTruncated = lines.takeLast().trimmed(); - QList searchResultList; + QVector searchResultList; + searchResultList.reserve(lines.size()); + for (const QByteArray &line : asConst(lines)) { SearchResult searchResult; if (parseSearchResult(QString::fromUtf8(line), searchResult)) @@ -141,7 +144,8 @@ void SearchHandler::readSearchOutput() } if (!searchResultList.isEmpty()) { - m_results.append(searchResultList); + for (const SearchResult &result : searchResultList) + m_results.append(result); emit newSearchResults(searchResultList); } } diff --git a/src/base/search/searchhandler.h b/src/base/search/searchhandler.h index 3cf71318a..c084fa82d 100644 --- a/src/base/search/searchhandler.h +++ b/src/base/search/searchhandler.h @@ -33,6 +33,7 @@ #include #include #include +#include class QProcess; class QTimer; @@ -71,7 +72,7 @@ public: signals: void searchFinished(bool cancelled = false); void searchFailed(); - void newSearchResults(const QList &results); + void newSearchResults(const QVector &results); private: void readSearchOutput(); diff --git a/src/base/utils/net.cpp b/src/base/utils/net.cpp index 5174fea61..fd11b3577 100644 --- a/src/base/utils/net.cpp +++ b/src/base/utils/net.cpp @@ -64,7 +64,7 @@ namespace Utils || (addr == QHostAddress(QLatin1String("::ffff:127.0.0.1"))); } - bool isIPInRange(const QHostAddress &addr, const QList &subnets) + bool isIPInRange(const QHostAddress &addr, const QVector &subnets) { QHostAddress protocolEquivalentAddress; bool addrConversionOk = false; diff --git a/src/base/utils/net.h b/src/base/utils/net.h index c5f59e828..ee2fa2f51 100644 --- a/src/base/utils/net.h +++ b/src/base/utils/net.h @@ -32,6 +32,7 @@ #include #include #include +#include class QSslCertificate; class QSslKey; @@ -47,7 +48,7 @@ namespace Utils Subnet parseSubnet(const QString &subnetStr, bool *ok = nullptr); bool canParseSubnet(const QString &subnetStr); bool isLoopbackAddress(const QHostAddress &addr); - bool isIPInRange(const QHostAddress &addr, const QList &subnets); + bool isIPInRange(const QHostAddress &addr, const QVector &subnets); QString subnetToString(const Subnet &subnet); const int MAX_SSL_FILE_SIZE = 1024 * 1024; diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index fa4f9473c..feda1608e 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -239,7 +239,7 @@ void PeerListWidget::showPeerListMenu(const QPoint &) const QAction *addPeerAct = menu->addAction(UIThemeManager::instance()->getIcon("user-group-new"), tr("Add a new peer...")); connect(addPeerAct, &QAction::triggered, this, [this, torrent]() { - const QList peersList = PeersAdditionDialog::askForPeers(this); + const QVector peersList = PeersAdditionDialog::askForPeers(this); int peerCount = 0; for (const BitTorrent::PeerAddress &addr : peersList) { if (torrent->connectPeer(addr)) { @@ -336,7 +336,7 @@ void PeerListWidget::loadPeers(BitTorrent::TorrentHandle *const torrent, bool fo { if (!torrent) return; - const QList peers = torrent->peers(); + const QVector peers = torrent->peers(); QSet oldPeersSet = m_peerItems.keys().toSet(); for (const BitTorrent::PeerInfo &peer : peers) { diff --git a/src/gui/properties/peersadditiondialog.cpp b/src/gui/properties/peersadditiondialog.cpp index f3396129a..2d18a5e5b 100644 --- a/src/gui/properties/peersadditiondialog.cpp +++ b/src/gui/properties/peersadditiondialog.cpp @@ -48,7 +48,7 @@ PeersAdditionDialog::~PeersAdditionDialog() delete m_ui; } -QList PeersAdditionDialog::askForPeers(QWidget *parent) +QVector PeersAdditionDialog::askForPeers(QWidget *parent) { PeersAdditionDialog dlg(parent); dlg.exec(); diff --git a/src/gui/properties/peersadditiondialog.h b/src/gui/properties/peersadditiondialog.h index ee8ddfc13..867be695e 100644 --- a/src/gui/properties/peersadditiondialog.h +++ b/src/gui/properties/peersadditiondialog.h @@ -30,7 +30,7 @@ #define PEERADDITION_H #include -#include +#include #include "base/bittorrent/peerinfo.h" @@ -47,14 +47,14 @@ public: PeersAdditionDialog(QWidget *parent); ~PeersAdditionDialog(); - static QList askForPeers(QWidget *parent); + static QVector askForPeers(QWidget *parent); protected slots: void validateInput(); private: Ui::PeersAdditionDialog *m_ui; - QList m_peersList; + QVector m_peersList; }; #endif // PEERADDITION_H diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index 0757c429e..97c64f32c 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -495,7 +495,7 @@ void PropertiesWidget::loadUrlSeeds() { m_ui->listWebSeeds->clear(); qDebug("Loading URL seeds"); - const QList hcSeeds = m_torrent->urlSeeds(); + const QVector hcSeeds = m_torrent->urlSeeds(); // Add url seeds for (const QUrl &hcSeed : hcSeeds) { qDebug("Loading URL seed: %s", qUtf8Printable(hcSeed.toString())); @@ -715,7 +715,7 @@ void PropertiesWidget::askWebSeed() return; } if (m_torrent) - m_torrent->addUrlSeeds(QList() << urlSeed); + m_torrent->addUrlSeeds({urlSeed}); // Refresh the seeds list loadUrlSeeds(); } @@ -725,7 +725,9 @@ void PropertiesWidget::deleteSelectedUrlSeeds() const QList selectedItems = m_ui->listWebSeeds->selectedItems(); if (selectedItems.isEmpty()) return; - QList urlSeeds; + QVector urlSeeds; + urlSeeds.reserve(selectedItems.size()); + for (const QListWidgetItem *item : selectedItems) urlSeeds << item->text(); @@ -766,8 +768,8 @@ void PropertiesWidget::editWebSeed() return; } - m_torrent->removeUrlSeeds(QList() << oldSeed); - m_torrent->addUrlSeeds(QList() << newSeed); + m_torrent->removeUrlSeeds({oldSeed}); + m_torrent->addUrlSeeds({newSeed}); loadUrlSeeds(); } diff --git a/src/gui/search/pluginselectdialog.cpp b/src/gui/search/pluginselectdialog.cpp index 937775be3..e6395c377 100644 --- a/src/gui/search/pluginselectdialog.cpp +++ b/src/gui/search/pluginselectdialog.cpp @@ -238,9 +238,10 @@ void PluginSelectDialog::setRowColor(const int row, const QString &color) } } -QList PluginSelectDialog::findItemsWithUrl(const QString &url) +QVector PluginSelectDialog::findItemsWithUrl(const QString &url) { - QList res; + QVector res; + res.reserve(m_ui->pluginsTree->topLevelItemCount()); for (int i = 0; i < m_ui->pluginsTree->topLevelItemCount(); ++i) { QTreeWidgetItem *item = m_ui->pluginsTree->topLevelItem(i); diff --git a/src/gui/search/pluginselectdialog.h b/src/gui/search/pluginselectdialog.h index 4406d0092..fe394d802 100644 --- a/src/gui/search/pluginselectdialog.h +++ b/src/gui/search/pluginselectdialog.h @@ -57,7 +57,7 @@ public: explicit PluginSelectDialog(SearchPluginManager *pluginManager, QWidget *parent = nullptr); ~PluginSelectDialog() override; - QList findItemsWithUrl(const QString &url); + QVector findItemsWithUrl(const QString &url); QTreeWidgetItem *findItemWithID(const QString &id); protected: diff --git a/src/gui/search/searchjobwidget.cpp b/src/gui/search/searchjobwidget.cpp index fdc1f566b..ebd97c766 100644 --- a/src/gui/search/searchjobwidget.cpp +++ b/src/gui/search/searchjobwidget.cpp @@ -506,7 +506,7 @@ void SearchJobWidget::searchFailed() setStatus(Status::Error); } -void SearchJobWidget::appendSearchResults(const QList &results) +void SearchJobWidget::appendSearchResults(const QVector &results) { for (const SearchResult &result : results) { // Add item to search result list diff --git a/src/gui/search/searchjobwidget.h b/src/gui/search/searchjobwidget.h index 9f1fbb83a..732208754 100644 --- a/src/gui/search/searchjobwidget.h +++ b/src/gui/search/searchjobwidget.h @@ -100,7 +100,7 @@ private: void onItemDoubleClicked(const QModelIndex &index); void searchFinished(bool cancelled); void searchFailed(); - void appendSearchResults(const QList &results); + void appendSearchResults(const QVector &results); void updateResultsCount(); void setStatus(Status value); void downloadTorrent(const QModelIndex &rowIndex); diff --git a/src/gui/torrentcontentmodel.cpp b/src/gui/torrentcontentmodel.cpp index d86a89a6f..5c81f94e3 100644 --- a/src/gui/torrentcontentmodel.cpp +++ b/src/gui/torrentcontentmodel.cpp @@ -198,7 +198,7 @@ namespace TorrentContentModel::TorrentContentModel(QObject *parent) : QAbstractItemModel(parent) - , m_rootItem(new TorrentContentModelFolder(QList({ tr("Name"), tr("Size"), tr("Progress"), tr("Download Priority"), tr("Remaining"), tr("Availability") }))) + , m_rootItem(new TorrentContentModelFolder(QVector({ tr("Name"), tr("Size"), tr("Progress"), tr("Download Priority"), tr("Remaining"), tr("Availability") }))) { #if defined(Q_OS_WIN) m_fileIconProvider = new WinShellFileIconProvider(); diff --git a/src/gui/torrentcontentmodelfolder.cpp b/src/gui/torrentcontentmodelfolder.cpp index 89c9147c3..55310b25e 100644 --- a/src/gui/torrentcontentmodelfolder.cpp +++ b/src/gui/torrentcontentmodelfolder.cpp @@ -43,7 +43,7 @@ TorrentContentModelFolder::TorrentContentModelFolder(const QString &name, Torren m_name.chop(4); } -TorrentContentModelFolder::TorrentContentModelFolder(const QList &data) +TorrentContentModelFolder::TorrentContentModelFolder(const QVector &data) : TorrentContentModelItem(nullptr) { Q_ASSERT(data.size() == NB_COL); @@ -67,7 +67,7 @@ void TorrentContentModelFolder::deleteAllChildren() m_childItems.clear(); } -const QList &TorrentContentModelFolder::children() const +const QVector &TorrentContentModelFolder::children() const { return m_childItems; } diff --git a/src/gui/torrentcontentmodelfolder.h b/src/gui/torrentcontentmodelfolder.h index a8dfcf3b0..55ec68075 100644 --- a/src/gui/torrentcontentmodelfolder.h +++ b/src/gui/torrentcontentmodelfolder.h @@ -43,7 +43,7 @@ public: TorrentContentModelFolder(const QString &name, TorrentContentModelFolder *parent); // Invisible root item constructor - explicit TorrentContentModelFolder(const QList &data); + explicit TorrentContentModelFolder(const QVector &data); ~TorrentContentModelFolder() override; @@ -57,14 +57,14 @@ public: void setPriority(BitTorrent::DownloadPriority newPriority, bool updateParent = true) override; void deleteAllChildren(); - const QList &children() const; + const QVector &children() const; void appendChild(TorrentContentModelItem *item); TorrentContentModelItem *child(int row) const; TorrentContentModelFolder *childFolderWithName(const QString &name) const; int childCount() const; private: - QList m_childItems; + QVector m_childItems; }; #endif // TORRENTCONTENTMODELFOLDER_H diff --git a/src/gui/torrentcontentmodelitem.h b/src/gui/torrentcontentmodelitem.h index e246d4a1b..c0a532ce2 100644 --- a/src/gui/torrentcontentmodelitem.h +++ b/src/gui/torrentcontentmodelitem.h @@ -29,7 +29,7 @@ #ifndef TORRENTCONTENTMODELITEM_H #define TORRENTCONTENTMODELITEM_H -#include +#include #include "base/bittorrent/downloadpriority.h" @@ -83,7 +83,7 @@ public: protected: TorrentContentModelFolder *m_parentItem; // Root item members - QList m_itemData; + QVector m_itemData; // Non-root item members QString m_name; qulonglong m_size; diff --git a/src/webui/api/synccontroller.cpp b/src/webui/api/synccontroller.cpp index c3eecb6b8..d11952eee 100644 --- a/src/webui/api/synccontroller.cpp +++ b/src/webui/api/synccontroller.cpp @@ -490,7 +490,8 @@ void SyncController::torrentPeersAction() QVariantMap data; QVariantHash peers; - const QList peersList = torrent->peers(); + + const QVector peersList = torrent->peers(); #ifndef DISABLE_COUNTRIES_RESOLUTION bool resolvePeerCountries = Preferences::instance()->resolvePeerCountries(); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index c6fb53811..fc22e540e 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -145,7 +145,7 @@ private: bool m_isLocalAuthEnabled; bool m_isAuthSubnetWhitelistEnabled; - QList m_authSubnetWhitelist; + QVector m_authSubnetWhitelist; int m_sessionTimeout; // security related From d92bf137061518c626ef941818b770c90eaac287 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 3 Aug 2019 17:18:41 +0800 Subject: [PATCH 2/2] Use a QString directly instead of QStringList --- src/base/bittorrent/peerinfo.cpp | 59 +++++++++++++------------------- src/base/bittorrent/peerinfo.h | 1 - 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/base/bittorrent/peerinfo.cpp b/src/base/bittorrent/peerinfo.cpp index 1a1215ee9..637ac7b36 100644 --- a/src/base/bittorrent/peerinfo.cpp +++ b/src/base/bittorrent/peerinfo.cpp @@ -33,7 +33,6 @@ #include "base/bittorrent/torrenthandle.h" #include "base/net/geoipmanager.h" #include "base/unicodestrings.h" -#include "base/utils/string.h" #include "peeraddress.h" using namespace BitTorrent; @@ -261,20 +260,18 @@ qreal PeerInfo::relevance() const void PeerInfo::determineFlags() { - QStringList flagsDescriptionList; - if (isInteresting()) { // d = Your client wants to download, but peer doesn't want to send (interested and choked) if (isRemoteChocked()) { m_flags += "d "; - flagsDescriptionList += "d = " - + tr("Interested(local) and Choked(peer)"); + m_flagsDescription += ("d = " + + tr("Interested(local) and Choked(peer)") + '\n'); } else { // D = Currently downloading (interested and not choked) m_flags += "D "; - flagsDescriptionList += "D = " - + tr("interested(local) and unchoked(peer)"); + m_flagsDescription += ("D = " + + tr("interested(local) and unchoked(peer)") + '\n'); } } @@ -282,95 +279,87 @@ void PeerInfo::determineFlags() // u = Peer wants your client to upload, but your client doesn't want to (interested and choked) if (isChocked()) { m_flags += "u "; - flagsDescriptionList += "u = " - + tr("interested(peer) and choked(local)"); + m_flagsDescription += ("u = " + + tr("interested(peer) and choked(local)") + '\n'); } else { // U = Currently uploading (interested and not choked) m_flags += "U "; - flagsDescriptionList += "U = " - + tr("interested(peer) and unchoked(local)"); + m_flagsDescription += ("U = " + + tr("interested(peer) and unchoked(local)") + '\n'); } } // O = Optimistic unchoke if (optimisticUnchoke()) { m_flags += "O "; - flagsDescriptionList += "O = " - + tr("optimistic unchoke"); + m_flagsDescription += ("O = " + tr("optimistic unchoke") + '\n'); } // S = Peer is snubbed if (isSnubbed()) { m_flags += "S "; - flagsDescriptionList += "S = " - + tr("peer snubbed"); + m_flagsDescription += ("S = " + tr("peer snubbed") + '\n'); } // I = Peer is an incoming connection if (!isLocalConnection()) { m_flags += "I "; - flagsDescriptionList += "I = " - + tr("incoming connection"); + m_flagsDescription += ("I = " + tr("incoming connection") + '\n'); } // K = Peer is unchoking your client, but your client is not interested if (!isRemoteChocked() && !isInteresting()) { m_flags += "K "; - flagsDescriptionList += "K = " - + tr("not interested(local) and unchoked(peer)"); + m_flagsDescription += ("K = " + + tr("not interested(local) and unchoked(peer)") + '\n'); } // ? = Your client unchoked the peer but the peer is not interested if (!isChocked() && !isRemoteInterested()) { m_flags += "? "; - flagsDescriptionList += "? = " - + tr("not interested(peer) and unchoked(local)"); + m_flagsDescription += ("? = " + + tr("not interested(peer) and unchoked(local)") + '\n'); } // X = Peer was included in peerlists obtained through Peer Exchange (PEX) if (fromPeX()) { m_flags += "X "; - flagsDescriptionList += "X = " - + tr("peer from PEX"); + m_flagsDescription += ("X = " + tr("peer from PEX") + '\n'); } // H = Peer was obtained through DHT if (fromDHT()) { m_flags += "H "; - flagsDescriptionList += "H = " - + tr("peer from DHT"); + m_flagsDescription += ("H = " + tr("peer from DHT") + '\n'); } // E = Peer is using Protocol Encryption (all traffic) if (isRC4Encrypted()) { m_flags += "E "; - flagsDescriptionList += "E = " - + tr("encrypted traffic"); + m_flagsDescription += ("E = " + tr("encrypted traffic") + '\n'); } // e = Peer is using Protocol Encryption (handshake) if (isPlaintextEncrypted()) { m_flags += "e "; - flagsDescriptionList += "e = " - + tr("encrypted handshake"); + m_flagsDescription += ("e = " + tr("encrypted handshake") + '\n'); } // P = Peer is using uTorrent uTP if (useUTPSocket()) { m_flags += "P "; - flagsDescriptionList += "P = " - + QString::fromUtf8(C_UTP); + m_flagsDescription += ("P = " + QString::fromUtf8(C_UTP) + '\n'); } // L = Peer is local if (fromLSD()) { - m_flags += 'L'; - flagsDescriptionList += "L = " - + tr("peer from LSD"); + m_flags += "L "; + m_flagsDescription += ("L = " + tr("peer from LSD") + '\n'); } + m_flags = m_flags.trimmed(); - m_flagsDescription = flagsDescriptionList.join('\n'); + m_flagsDescription = m_flagsDescription.trimmed(); } QString PeerInfo::flags() const diff --git a/src/base/bittorrent/peerinfo.h b/src/base/bittorrent/peerinfo.h index 5ba7b1e3a..328cabf4c 100644 --- a/src/base/bittorrent/peerinfo.h +++ b/src/base/bittorrent/peerinfo.h @@ -32,7 +32,6 @@ #include #include -#include class QBitArray;