mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-14 09:13:08 -07:00
Use InfoHash type in queueing operations
This avoids redundant type conversions.
This commit is contained in:
parent
a9e6ef183b
commit
e0a23ba93d
4 changed files with 59 additions and 43 deletions
|
@ -33,6 +33,7 @@
|
|||
#include <cstdlib>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <wincrypt.h>
|
||||
|
@ -1699,22 +1700,23 @@ bool Session::cancelLoadMetadata(const InfoHash &hash)
|
|||
return true;
|
||||
}
|
||||
|
||||
void Session::increaseTorrentsQueuePos(const QStringList &hashes)
|
||||
void Session::increaseTorrentsQueuePos(const QVector<InfoHash> &hashes)
|
||||
{
|
||||
std::priority_queue<QPair<int, TorrentHandle *>,
|
||||
std::vector<QPair<int, TorrentHandle *>>,
|
||||
std::greater<QPair<int, TorrentHandle *>>> torrentQueue;
|
||||
using ElementType = std::pair<int, TorrentHandle *>;
|
||||
std::priority_queue<ElementType
|
||||
, std::vector<ElementType>
|
||||
, std::greater<ElementType>> torrentQueue;
|
||||
|
||||
// Sort torrents by queue position
|
||||
for (const InfoHash infoHash : hashes) {
|
||||
for (const InfoHash &infoHash : hashes) {
|
||||
TorrentHandle *const torrent = m_torrents.value(infoHash);
|
||||
if (torrent && !torrent->isSeed())
|
||||
torrentQueue.push(qMakePair(torrent->queuePosition(), torrent));
|
||||
torrentQueue.emplace(torrent->queuePosition(), torrent);
|
||||
}
|
||||
|
||||
// Increase torrents queue position (starting with the one in the highest queue position)
|
||||
while (!torrentQueue.empty()) {
|
||||
TorrentHandle *const torrent = torrentQueue.top().second;
|
||||
const TorrentHandle *torrent = torrentQueue.top().second;
|
||||
torrentQueuePositionUp(torrent->nativeHandle());
|
||||
torrentQueue.pop();
|
||||
}
|
||||
|
@ -1722,22 +1724,21 @@ void Session::increaseTorrentsQueuePos(const QStringList &hashes)
|
|||
saveTorrentsQueue();
|
||||
}
|
||||
|
||||
void Session::decreaseTorrentsQueuePos(const QStringList &hashes)
|
||||
void Session::decreaseTorrentsQueuePos(const QVector<InfoHash> &hashes)
|
||||
{
|
||||
std::priority_queue<QPair<int, TorrentHandle *>,
|
||||
std::vector<QPair<int, TorrentHandle *>>,
|
||||
std::less<QPair<int, TorrentHandle *>>> torrentQueue;
|
||||
using ElementType = std::pair<int, TorrentHandle *>;
|
||||
std::priority_queue<ElementType> torrentQueue;
|
||||
|
||||
// Sort torrents by queue position
|
||||
for (const InfoHash infoHash : hashes) {
|
||||
for (const InfoHash &infoHash : hashes) {
|
||||
TorrentHandle *const torrent = m_torrents.value(infoHash);
|
||||
if (torrent && !torrent->isSeed())
|
||||
torrentQueue.push(qMakePair(torrent->queuePosition(), torrent));
|
||||
torrentQueue.emplace(torrent->queuePosition(), torrent);
|
||||
}
|
||||
|
||||
// Decrease torrents queue position (starting with the one in the lowest queue position)
|
||||
while (!torrentQueue.empty()) {
|
||||
TorrentHandle *const torrent = torrentQueue.top().second;
|
||||
const TorrentHandle *torrent = torrentQueue.top().second;
|
||||
torrentQueuePositionDown(torrent->nativeHandle());
|
||||
torrentQueue.pop();
|
||||
}
|
||||
|
@ -1748,22 +1749,23 @@ void Session::decreaseTorrentsQueuePos(const QStringList &hashes)
|
|||
saveTorrentsQueue();
|
||||
}
|
||||
|
||||
void Session::topTorrentsQueuePos(const QStringList &hashes)
|
||||
void Session::topTorrentsQueuePos(const QVector<InfoHash> &hashes)
|
||||
{
|
||||
std::priority_queue<QPair<int, TorrentHandle *>,
|
||||
std::vector<QPair<int, TorrentHandle *>>,
|
||||
std::greater<QPair<int, TorrentHandle *>>> torrentQueue;
|
||||
using ElementType = std::pair<int, TorrentHandle *>;
|
||||
std::priority_queue<ElementType
|
||||
, std::vector<ElementType>
|
||||
, std::greater<ElementType>> torrentQueue;
|
||||
|
||||
// Sort torrents by queue position
|
||||
for (const InfoHash infoHash : hashes) {
|
||||
for (const InfoHash &infoHash : hashes) {
|
||||
TorrentHandle *const torrent = m_torrents.value(infoHash);
|
||||
if (torrent && !torrent->isSeed())
|
||||
torrentQueue.push(qMakePair(torrent->queuePosition(), torrent));
|
||||
torrentQueue.emplace(torrent->queuePosition(), torrent);
|
||||
}
|
||||
|
||||
// Top torrents queue position (starting with the one in the highest queue position)
|
||||
while (!torrentQueue.empty()) {
|
||||
TorrentHandle *const torrent = torrentQueue.top().second;
|
||||
const TorrentHandle *torrent = torrentQueue.top().second;
|
||||
torrentQueuePositionTop(torrent->nativeHandle());
|
||||
torrentQueue.pop();
|
||||
}
|
||||
|
@ -1771,22 +1773,23 @@ void Session::topTorrentsQueuePos(const QStringList &hashes)
|
|||
saveTorrentsQueue();
|
||||
}
|
||||
|
||||
void Session::bottomTorrentsQueuePos(const QStringList &hashes)
|
||||
void Session::bottomTorrentsQueuePos(const QVector<InfoHash> &hashes)
|
||||
{
|
||||
std::priority_queue<QPair<int, TorrentHandle *>,
|
||||
std::vector<QPair<int, TorrentHandle *>>,
|
||||
std::less<QPair<int, TorrentHandle *>>> torrentQueue;
|
||||
using ElementType = std::pair<int, TorrentHandle *>;
|
||||
std::priority_queue<ElementType
|
||||
, std::vector<ElementType>
|
||||
, std::less<ElementType>> torrentQueue;
|
||||
|
||||
// Sort torrents by queue position
|
||||
for (const InfoHash infoHash : hashes) {
|
||||
for (const InfoHash &infoHash : hashes) {
|
||||
TorrentHandle *const torrent = m_torrents.value(infoHash);
|
||||
if (torrent && !torrent->isSeed())
|
||||
torrentQueue.push(qMakePair(torrent->queuePosition(), torrent));
|
||||
torrentQueue.emplace(torrent->queuePosition(), torrent);
|
||||
}
|
||||
|
||||
// Bottom torrents queue position (starting with the one in the lowest queue position)
|
||||
while (!torrentQueue.empty()) {
|
||||
TorrentHandle *const torrent = torrentQueue.top().second;
|
||||
const TorrentHandle *torrent = torrentQueue.top().second;
|
||||
torrentQueuePositionBottom(torrent->nativeHandle());
|
||||
torrentQueue.pop();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue