Replace QList by QVector

This commit is contained in:
Chocobo1
2019-08-02 12:55:06 +08:00
parent 6cc7c700b8
commit e90a2c00a5
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;