Replace QList by QVector

This commit is contained in:
Chocobo1 2019-08-02 12:55:06 +08:00
parent 6cc7c700b8
commit e90a2c00a5
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
30 changed files with 94 additions and 73 deletions

View file

@ -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<TrackerEntry> MagnetUri::trackers() const
return m_trackers;
}
QList<QUrl> MagnetUri::urlSeeds() const
QVector<QUrl> MagnetUri::urlSeeds() const
{
return m_urlSeeds;
}

View file

@ -31,7 +31,6 @@
#include <libtorrent/add_torrent_params.hpp>
#include <QList>
#include <QString>
#include <QVector>
@ -51,7 +50,7 @@ namespace BitTorrent
InfoHash hash() const;
QString name() const;
QVector<TrackerEntry> trackers() const;
QList<QUrl> urlSeeds() const;
QVector<QUrl> urlSeeds() const;
QString url() const;
lt::add_torrent_params addTorrentParams() const;
@ -62,7 +61,7 @@ namespace BitTorrent
InfoHash m_hash;
QString m_name;
QVector<TrackerEntry> m_trackers;
QList<QUrl> m_urlSeeds;
QVector<QUrl> m_urlSeeds;
lt::add_torrent_params m_addTorrentParams;
};
}

View file

@ -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;
};

View file

@ -3409,14 +3409,14 @@ void Session::handleTorrentTrackersChanged(TorrentHandle *const torrent)
emit trackersChanged(torrent);
}
void Session::handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QList<QUrl> &newUrlSeeds)
void Session::handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QVector<QUrl> &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<QUrl> &urlSeeds)
void Session::handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QVector<QUrl> &urlSeeds)
{
torrent->saveResumeData();
for (const QUrl &urlSeed : urlSeeds)

View file

@ -36,10 +36,10 @@
#include <QFile>
#include <QHash>
#include <QList>
#include <QNetworkConfigurationManager>
#include <QPointer>
#include <QSet>
#include <QVector>
#include "base/settingvalue.h"
#include "base/types.h"
@ -439,8 +439,8 @@ namespace BitTorrent
void handleTorrentTrackersAdded(TorrentHandle *const torrent, const QVector<TrackerEntry> &newTrackers);
void handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QVector<TrackerEntry> &deletedTrackers);
void handleTorrentTrackersChanged(TorrentHandle *const torrent);
void handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QList<QUrl> &newUrlSeeds);
void handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QList<QUrl> &urlSeeds);
void handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QVector<QUrl> &newUrlSeeds);
void handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QVector<QUrl> &urlSeeds);
void handleTorrentResumeDataReady(TorrentHandle *const torrent, const lt::entry &data);
void handleTorrentResumeDataFailed(TorrentHandle *const torrent);
void handleTorrentTrackerReply(TorrentHandle *const torrent, const QString &trackerUrl);

View file

@ -475,20 +475,23 @@ void TorrentHandle::replaceTrackers(const QVector<TrackerEntry> &trackers)
}
}
QList<QUrl> TorrentHandle::urlSeeds() const
QVector<QUrl> TorrentHandle::urlSeeds() const
{
QList<QUrl> urlSeeds;
const std::set<std::string> seeds = m_nativeHandle.url_seeds();
QVector<QUrl> urlSeeds;
urlSeeds.reserve(seeds.size());
for (const std::string &urlSeed : seeds)
urlSeeds.append(QUrl(urlSeed.c_str()));
return urlSeeds;
}
void TorrentHandle::addUrlSeeds(const QList<QUrl> &urlSeeds)
void TorrentHandle::addUrlSeeds(const QVector<QUrl> &urlSeeds)
{
QList<QUrl> addedUrlSeeds;
QVector<QUrl> addedUrlSeeds;
addedUrlSeeds.reserve(urlSeeds.size());
for (const QUrl &urlSeed : urlSeeds) {
if (addUrlSeed(urlSeed))
addedUrlSeeds << urlSeed;
@ -498,9 +501,10 @@ void TorrentHandle::addUrlSeeds(const QList<QUrl> &urlSeeds)
m_session->handleTorrentUrlSeedsAdded(this, addedUrlSeeds);
}
void TorrentHandle::removeUrlSeeds(const QList<QUrl> &urlSeeds)
void TorrentHandle::removeUrlSeeds(const QVector<QUrl> &urlSeeds)
{
QList<QUrl> removedUrlSeeds;
QVector<QUrl> removedUrlSeeds;
removedUrlSeeds.reserve(urlSeeds.size());
for (const QUrl &urlSeed : urlSeeds) {
if (removeUrlSeed(urlSeed))
removedUrlSeeds << urlSeed;
@ -512,7 +516,7 @@ void TorrentHandle::removeUrlSeeds(const QList<QUrl> &urlSeeds)
bool TorrentHandle::addUrlSeed(const QUrl &urlSeed)
{
QList<QUrl> seeds = urlSeeds();
const QVector<QUrl> 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<QUrl> seeds = urlSeeds();
const QVector<QUrl> 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<PeerInfo> TorrentHandle::peers() const
QVector<PeerInfo> TorrentHandle::peers() const
{
QList<PeerInfo> peers;
std::vector<lt::peer_info> nativePeers;
m_nativeHandle.get_peer_info(nativePeers);
QVector<PeerInfo> peers;
peers.reserve(nativePeers.size());
for (const lt::peer_info &peer : nativePeers)
peers << PeerInfo(this, peer);
return peers;
}

View file

@ -37,7 +37,6 @@
#include <libtorrent/torrent_status.hpp>
#include <QHash>
#include <QList>
#include <QObject>
#include <QQueue>
#include <QSet>
@ -263,7 +262,7 @@ namespace BitTorrent
int queuePosition() const;
QVector<TrackerEntry> trackers() const;
QHash<QString, TrackerInfo> trackerInfos() const;
QList<QUrl> urlSeeds() const;
QVector<QUrl> 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<PeerInfo> peers() const;
QVector<PeerInfo> peers() const;
QBitArray pieces() const;
QBitArray downloadingPieces() const;
QVector<int> pieceAvailability() const;
@ -326,8 +325,8 @@ namespace BitTorrent
void flushCache();
void addTrackers(const QVector<TrackerEntry> &trackers);
void replaceTrackers(const QVector<TrackerEntry> &trackers);
void addUrlSeeds(const QList<QUrl> &urlSeeds);
void removeUrlSeeds(const QList<QUrl> &urlSeeds);
void addUrlSeeds(const QVector<QUrl> &urlSeeds);
void removeUrlSeeds(const QVector<QUrl> &urlSeeds);
bool connectPeer(const PeerAddress &peerAddress);
QString toMagnetUri() const;

View file

@ -278,14 +278,19 @@ QVector<TrackerEntry> TorrentInfo::trackers() const
return ret;
}
QList<QUrl> TorrentInfo::urlSeeds() const
QVector<QUrl> TorrentInfo::urlSeeds() const
{
if (!isValid()) return {};
QList<QUrl> urlSeeds;
for (const lt::web_seed_entry &webSeed : m_nativeInfo->web_seeds())
const std::vector<lt::web_seed_entry> &nativeWebSeeds = m_nativeInfo->web_seeds();
QVector<QUrl> 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;
}

View file

@ -33,7 +33,6 @@
#include <libtorrent/version.hpp>
#include <QCoreApplication>
#include <QList>
#include <QVector>
#include "base/indexrange.h"
@ -89,7 +88,7 @@ namespace BitTorrent
qlonglong fileSize(int index) const;
qlonglong fileOffset(int index) const;
QVector<TrackerEntry> trackers() const;
QList<QUrl> urlSeeds() const;
QVector<QUrl> urlSeeds() const;
QByteArray metadata() const;
QStringList filesForPiece(int pieceIndex) const;
QVector<int> fileIndicesForPiece(int pieceIndex) const;

View file

@ -32,8 +32,8 @@
#include <QDir>
#include <QFileSystemWatcher>
#include <QHash>
#include <QList>
#include <QTimer>
#include <QVector>
class QStringList;
@ -67,7 +67,7 @@ private:
QHash<QString, int> m_partialTorrents;
QTimer m_partialTorrentTimer;
QList<QDir> m_watchedFolders;
QVector<QDir> m_watchedFolders;
QTimer m_watchTimer;
};

View file

@ -528,17 +528,21 @@ void Preferences::setWebUiAuthSubnetWhitelistEnabled(const bool enabled)
setValue("Preferences/WebUI/AuthSubnetWhitelistEnabled", enabled);
}
QList<Utils::Net::Subnet> Preferences::getWebUiAuthSubnetWhitelist() const
QVector<Utils::Net::Subnet> Preferences::getWebUiAuthSubnetWhitelist() const
{
QList<Utils::Net::Subnet> subnets;
for (const QString &rawSubnet : asConst(value("Preferences/WebUI/AuthSubnetWhitelist").toStringList())) {
const QStringList subnets = value("Preferences/WebUI/AuthSubnetWhitelist").toStringList();
QVector<Utils::Net::Subnet> 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)

View file

@ -188,7 +188,7 @@ public:
void setWebUiLocalAuthEnabled(bool enabled);
bool isWebUiAuthSubnetWhitelistEnabled() const;
void setWebUiAuthSubnetWhitelistEnabled(bool enabled);
QList<Utils::Net::Subnet> getWebUiAuthSubnetWhitelist() const;
QVector<Utils::Net::Subnet> getWebUiAuthSubnetWhitelist() const;
void setWebUiAuthSubnetWhitelist(QStringList subnets);
QString getWebUiUsername() const;
void setWebUiUsername(const QString &username);

View file

@ -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<QByteArray> lines = output.split('\n');
if (!m_searchResultLineTruncated.isEmpty())
lines.prepend(m_searchResultLineTruncated + lines.takeFirst());
m_searchResultLineTruncated = lines.takeLast().trimmed();
QList<SearchResult> searchResultList;
QVector<SearchResult> 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);
}
}

View file

@ -33,6 +33,7 @@
#include <QList>
#include <QObject>
#include <QString>
#include <QVector>
class QProcess;
class QTimer;
@ -71,7 +72,7 @@ public:
signals:
void searchFinished(bool cancelled = false);
void searchFailed();
void newSearchResults(const QList<SearchResult> &results);
void newSearchResults(const QVector<SearchResult> &results);
private:
void readSearchOutput();

View file

@ -64,7 +64,7 @@ namespace Utils
|| (addr == QHostAddress(QLatin1String("::ffff:127.0.0.1")));
}
bool isIPInRange(const QHostAddress &addr, const QList<Subnet> &subnets)
bool isIPInRange(const QHostAddress &addr, const QVector<Subnet> &subnets)
{
QHostAddress protocolEquivalentAddress;
bool addrConversionOk = false;

View file

@ -32,6 +32,7 @@
#include <QHostAddress>
#include <QList>
#include <QPair>
#include <QVector>
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<Subnet> &subnets);
bool isIPInRange(const QHostAddress &addr, const QVector<Subnet> &subnets);
QString subnetToString(const Subnet &subnet);
const int MAX_SSL_FILE_SIZE = 1024 * 1024;

View file

@ -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<BitTorrent::PeerAddress> peersList = PeersAdditionDialog::askForPeers(this);
const QVector<BitTorrent::PeerAddress> 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<BitTorrent::PeerInfo> peers = torrent->peers();
const QVector<BitTorrent::PeerInfo> peers = torrent->peers();
QSet<QString> oldPeersSet = m_peerItems.keys().toSet();
for (const BitTorrent::PeerInfo &peer : peers) {

View file

@ -48,7 +48,7 @@ PeersAdditionDialog::~PeersAdditionDialog()
delete m_ui;
}
QList<BitTorrent::PeerAddress> PeersAdditionDialog::askForPeers(QWidget *parent)
QVector<BitTorrent::PeerAddress> PeersAdditionDialog::askForPeers(QWidget *parent)
{
PeersAdditionDialog dlg(parent);
dlg.exec();

View file

@ -30,7 +30,7 @@
#define PEERADDITION_H
#include <QDialog>
#include <QList>
#include <QVector>
#include "base/bittorrent/peerinfo.h"
@ -47,14 +47,14 @@ public:
PeersAdditionDialog(QWidget *parent);
~PeersAdditionDialog();
static QList<BitTorrent::PeerAddress> askForPeers(QWidget *parent);
static QVector<BitTorrent::PeerAddress> askForPeers(QWidget *parent);
protected slots:
void validateInput();
private:
Ui::PeersAdditionDialog *m_ui;
QList<BitTorrent::PeerAddress> m_peersList;
QVector<BitTorrent::PeerAddress> m_peersList;
};
#endif // PEERADDITION_H

View file

@ -495,7 +495,7 @@ void PropertiesWidget::loadUrlSeeds()
{
m_ui->listWebSeeds->clear();
qDebug("Loading URL seeds");
const QList<QUrl> hcSeeds = m_torrent->urlSeeds();
const QVector<QUrl> 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<QUrl>() << urlSeed);
m_torrent->addUrlSeeds({urlSeed});
// Refresh the seeds list
loadUrlSeeds();
}
@ -725,7 +725,9 @@ void PropertiesWidget::deleteSelectedUrlSeeds()
const QList<QListWidgetItem *> selectedItems = m_ui->listWebSeeds->selectedItems();
if (selectedItems.isEmpty()) return;
QList<QUrl> urlSeeds;
QVector<QUrl> 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<QUrl>() << oldSeed);
m_torrent->addUrlSeeds(QList<QUrl>() << newSeed);
m_torrent->removeUrlSeeds({oldSeed});
m_torrent->addUrlSeeds({newSeed});
loadUrlSeeds();
}

View file

@ -238,9 +238,10 @@ void PluginSelectDialog::setRowColor(const int row, const QString &color)
}
}
QList<QTreeWidgetItem*> PluginSelectDialog::findItemsWithUrl(const QString &url)
QVector<QTreeWidgetItem*> PluginSelectDialog::findItemsWithUrl(const QString &url)
{
QList<QTreeWidgetItem*> res;
QVector<QTreeWidgetItem*> res;
res.reserve(m_ui->pluginsTree->topLevelItemCount());
for (int i = 0; i < m_ui->pluginsTree->topLevelItemCount(); ++i) {
QTreeWidgetItem *item = m_ui->pluginsTree->topLevelItem(i);

View file

@ -57,7 +57,7 @@ public:
explicit PluginSelectDialog(SearchPluginManager *pluginManager, QWidget *parent = nullptr);
~PluginSelectDialog() override;
QList<QTreeWidgetItem*> findItemsWithUrl(const QString &url);
QVector<QTreeWidgetItem*> findItemsWithUrl(const QString &url);
QTreeWidgetItem *findItemWithID(const QString &id);
protected:

View file

@ -506,7 +506,7 @@ void SearchJobWidget::searchFailed()
setStatus(Status::Error);
}
void SearchJobWidget::appendSearchResults(const QList<SearchResult> &results)
void SearchJobWidget::appendSearchResults(const QVector<SearchResult> &results)
{
for (const SearchResult &result : results) {
// Add item to search result list

View file

@ -100,7 +100,7 @@ private:
void onItemDoubleClicked(const QModelIndex &index);
void searchFinished(bool cancelled);
void searchFailed();
void appendSearchResults(const QList<SearchResult> &results);
void appendSearchResults(const QVector<SearchResult> &results);
void updateResultsCount();
void setStatus(Status value);
void downloadTorrent(const QModelIndex &rowIndex);

View file

@ -198,7 +198,7 @@ namespace
TorrentContentModel::TorrentContentModel(QObject *parent)
: QAbstractItemModel(parent)
, m_rootItem(new TorrentContentModelFolder(QList<QVariant>({ tr("Name"), tr("Size"), tr("Progress"), tr("Download Priority"), tr("Remaining"), tr("Availability") })))
, m_rootItem(new TorrentContentModelFolder(QVector<QVariant>({ tr("Name"), tr("Size"), tr("Progress"), tr("Download Priority"), tr("Remaining"), tr("Availability") })))
{
#if defined(Q_OS_WIN)
m_fileIconProvider = new WinShellFileIconProvider();

View file

@ -43,7 +43,7 @@ TorrentContentModelFolder::TorrentContentModelFolder(const QString &name, Torren
m_name.chop(4);
}
TorrentContentModelFolder::TorrentContentModelFolder(const QList<QVariant> &data)
TorrentContentModelFolder::TorrentContentModelFolder(const QVector<QVariant> &data)
: TorrentContentModelItem(nullptr)
{
Q_ASSERT(data.size() == NB_COL);
@ -67,7 +67,7 @@ void TorrentContentModelFolder::deleteAllChildren()
m_childItems.clear();
}
const QList<TorrentContentModelItem *> &TorrentContentModelFolder::children() const
const QVector<TorrentContentModelItem *> &TorrentContentModelFolder::children() const
{
return m_childItems;
}

View file

@ -43,7 +43,7 @@ public:
TorrentContentModelFolder(const QString &name, TorrentContentModelFolder *parent);
// Invisible root item constructor
explicit TorrentContentModelFolder(const QList<QVariant> &data);
explicit TorrentContentModelFolder(const QVector<QVariant> &data);
~TorrentContentModelFolder() override;
@ -57,14 +57,14 @@ public:
void setPriority(BitTorrent::DownloadPriority newPriority, bool updateParent = true) override;
void deleteAllChildren();
const QList<TorrentContentModelItem*> &children() const;
const QVector<TorrentContentModelItem*> &children() const;
void appendChild(TorrentContentModelItem *item);
TorrentContentModelItem *child(int row) const;
TorrentContentModelFolder *childFolderWithName(const QString &name) const;
int childCount() const;
private:
QList<TorrentContentModelItem*> m_childItems;
QVector<TorrentContentModelItem*> m_childItems;
};
#endif // TORRENTCONTENTMODELFOLDER_H

View file

@ -29,7 +29,7 @@
#ifndef TORRENTCONTENTMODELITEM_H
#define TORRENTCONTENTMODELITEM_H
#include <QList>
#include <QVector>
#include "base/bittorrent/downloadpriority.h"
@ -83,7 +83,7 @@ public:
protected:
TorrentContentModelFolder *m_parentItem;
// Root item members
QList<QVariant> m_itemData;
QVector<QVariant> m_itemData;
// Non-root item members
QString m_name;
qulonglong m_size;

View file

@ -490,7 +490,8 @@ void SyncController::torrentPeersAction()
QVariantMap data;
QVariantHash peers;
const QList<BitTorrent::PeerInfo> peersList = torrent->peers();
const QVector<BitTorrent::PeerInfo> peersList = torrent->peers();
#ifndef DISABLE_COUNTRIES_RESOLUTION
bool resolvePeerCountries = Preferences::instance()->resolvePeerCountries();

View file

@ -145,7 +145,7 @@ private:
bool m_isLocalAuthEnabled;
bool m_isAuthSubnetWhitelistEnabled;
QList<Utils::Net::Subnet> m_authSubnetWhitelist;
QVector<Utils::Net::Subnet> m_authSubnetWhitelist;
int m_sessionTimeout;
// security related