Browse Source

Preserve relative order when moving to top/bottom in queue

Closes #11312.
adaptive-webui-19844
Chocobo1 5 years ago
parent
commit
021908320e
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 10
      src/base/bittorrent/session.cpp

10
src/base/bittorrent/session.cpp

@ -1752,9 +1752,7 @@ void Session::decreaseTorrentsQueuePos(const QVector<InfoHash> &hashes)
void Session::topTorrentsQueuePos(const QVector<InfoHash> &hashes) void Session::topTorrentsQueuePos(const QVector<InfoHash> &hashes)
{ {
using ElementType = std::pair<int, TorrentHandle *>; using ElementType = std::pair<int, TorrentHandle *>;
std::priority_queue<ElementType std::priority_queue<ElementType> torrentQueue;
, std::vector<ElementType>
, std::greater<ElementType>> torrentQueue;
// Sort torrents by queue position // Sort torrents by queue position
for (const InfoHash &infoHash : hashes) { for (const InfoHash &infoHash : hashes) {
@ -1763,7 +1761,7 @@ void Session::topTorrentsQueuePos(const QVector<InfoHash> &hashes)
torrentQueue.emplace(torrent->queuePosition(), torrent); torrentQueue.emplace(torrent->queuePosition(), torrent);
} }
// Top torrents queue position (starting with the one in the highest queue position) // Top torrents queue position (starting with the one in the lowest queue position)
while (!torrentQueue.empty()) { while (!torrentQueue.empty()) {
const TorrentHandle *torrent = torrentQueue.top().second; const TorrentHandle *torrent = torrentQueue.top().second;
torrentQueuePositionTop(torrent->nativeHandle()); torrentQueuePositionTop(torrent->nativeHandle());
@ -1778,7 +1776,7 @@ void Session::bottomTorrentsQueuePos(const QVector<InfoHash> &hashes)
using ElementType = std::pair<int, TorrentHandle *>; using ElementType = std::pair<int, TorrentHandle *>;
std::priority_queue<ElementType std::priority_queue<ElementType
, std::vector<ElementType> , std::vector<ElementType>
, std::less<ElementType>> torrentQueue; , std::greater<ElementType>> torrentQueue;
// Sort torrents by queue position // Sort torrents by queue position
for (const InfoHash &infoHash : hashes) { for (const InfoHash &infoHash : hashes) {
@ -1787,7 +1785,7 @@ void Session::bottomTorrentsQueuePos(const QVector<InfoHash> &hashes)
torrentQueue.emplace(torrent->queuePosition(), torrent); torrentQueue.emplace(torrent->queuePosition(), torrent);
} }
// Bottom torrents queue position (starting with the one in the lowest queue position) // Bottom torrents queue position (starting with the one in the highest queue position)
while (!torrentQueue.empty()) { while (!torrentQueue.empty()) {
const TorrentHandle *torrent = torrentQueue.top().second; const TorrentHandle *torrent = torrentQueue.top().second;
torrentQueuePositionBottom(torrent->nativeHandle()); torrentQueuePositionBottom(torrent->nativeHandle());

Loading…
Cancel
Save