Merge pull request #11319 from Chocobo1/backport

Preserve relative order when moving to top/bottom in queue (backport)
This commit is contained in:
Mike Tzou 2019-10-04 12:01:33 +08:00 committed by GitHub
commit 73fd4d83af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2034,7 +2034,7 @@ void Session::topTorrentsPriority(const QStringList &hashes)
{ {
std::priority_queue<QPair<int, TorrentHandle *>, std::priority_queue<QPair<int, TorrentHandle *>,
std::vector<QPair<int, TorrentHandle *>>, std::vector<QPair<int, TorrentHandle *>>,
std::greater<QPair<int, TorrentHandle *>>> torrentQueue; std::less<QPair<int, TorrentHandle *>>> torrentQueue;
// Sort torrents by priority // Sort torrents by priority
for (const InfoHash infoHash : hashes) { for (const InfoHash infoHash : hashes) {
@ -2043,7 +2043,7 @@ void Session::topTorrentsPriority(const QStringList &hashes)
torrentQueue.push(qMakePair(torrent->queuePosition(), torrent)); torrentQueue.push(qMakePair(torrent->queuePosition(), torrent));
} }
// Top torrents priority (starting with the ones with highest priority) // Top torrents priority (starting with the ones with lowest priority)
while (!torrentQueue.empty()) { while (!torrentQueue.empty()) {
TorrentHandle *const torrent = torrentQueue.top().second; TorrentHandle *const torrent = torrentQueue.top().second;
torrentQueuePositionTop(torrent->nativeHandle()); torrentQueuePositionTop(torrent->nativeHandle());
@ -2057,7 +2057,7 @@ void Session::bottomTorrentsPriority(const QStringList &hashes)
{ {
std::priority_queue<QPair<int, TorrentHandle *>, std::priority_queue<QPair<int, TorrentHandle *>,
std::vector<QPair<int, TorrentHandle *>>, std::vector<QPair<int, TorrentHandle *>>,
std::less<QPair<int, TorrentHandle *>>> torrentQueue; std::greater<QPair<int, TorrentHandle *>>> torrentQueue;
// Sort torrents by priority // Sort torrents by priority
for (const InfoHash infoHash : hashes) { for (const InfoHash infoHash : hashes) {
@ -2066,7 +2066,7 @@ void Session::bottomTorrentsPriority(const QStringList &hashes)
torrentQueue.push(qMakePair(torrent->queuePosition(), torrent)); torrentQueue.push(qMakePair(torrent->queuePosition(), torrent));
} }
// Bottom torrents priority (starting with the ones with lowest priority) // Bottom torrents priority (starting with the ones with highest priority)
while (!torrentQueue.empty()) { while (!torrentQueue.empty()) {
TorrentHandle *const torrent = torrentQueue.top().second; TorrentHandle *const torrent = torrentQueue.top().second;
torrentQueuePositionBottom(torrent->nativeHandle()); torrentQueuePositionBottom(torrent->nativeHandle());