From 0397176c10461be4e589fc2a9ef6eea709d27e7d Mon Sep 17 00:00:00 2001 From: Viacheslav Chimishuk Date: Fri, 17 Jun 2022 01:08:42 +0300 Subject: [PATCH] keep labels in order added, rather than alphabetically (#3271) --- libtransmission/resume.cc | 2 +- libtransmission/rpcimpl.cc | 2 +- libtransmission/torrent.cc | 16 +++++++++++----- libtransmission/torrent.h | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libtransmission/resume.cc b/libtransmission/resume.cc index b24162ca5..03a78e87a 100644 --- a/libtransmission/resume.cc +++ b/libtransmission/resume.cc @@ -119,7 +119,7 @@ static auto loadLabels(tr_variant* dict, tr_torrent* tor) } } - tor->setLabels(std::data(labels), std::size(labels)); + tor->setLabels(labels); return tr_resume::Labels; } diff --git a/libtransmission/rpcimpl.cc b/libtransmission/rpcimpl.cc index fc84be2fc..d1748433e 100644 --- a/libtransmission/rpcimpl.cc +++ b/libtransmission/rpcimpl.cc @@ -979,7 +979,7 @@ static char const* setLabels(tr_torrent* tor, tr_variant* list) return errmsg; } - tor->setLabels(std::data(labels), std::size(labels)); + tor->setLabels(labels); return nullptr; } diff --git a/libtransmission/torrent.cc b/libtransmission/torrent.cc index c61e1c508..68a50bf25 100644 --- a/libtransmission/torrent.cc +++ b/libtransmission/torrent.cc @@ -11,7 +11,6 @@ #include /* signal() */ #include #include -#include #include #include #include @@ -714,7 +713,7 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor) tor->finishedSeedingByIdle = false; auto const& labels = tr_ctorGetLabels(ctor); - tor->setLabels(std::data(labels), std::size(labels)); + tor->setLabels(labels); tor->uniqueId = session->torrents().add(tor); @@ -1909,11 +1908,18 @@ void tr_torrentSetFileDLs(tr_torrent* tor, tr_file_index_t const* files, tr_file **** ***/ -void tr_torrent::setLabels(tr_quark const* new_labels, size_t n_labels) +void tr_torrent::setLabels(std::vector const& new_labels) { auto const lock = unique_lock(); - auto const sorted_unique = std::set{ new_labels, new_labels + n_labels }; - this->labels = { std::begin(sorted_unique), std::end(sorted_unique) }; + this->labels.clear(); + + for (auto label : new_labels) + { + if (std::find(std::begin(this->labels), std::end(this->labels), label) == std::end(this->labels)) + { + this->labels.push_back(label); + } + } this->labels.shrink_to_fit(); this->setDirty(); } diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index 92d654177..948f07c00 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -581,7 +581,7 @@ public: void setDateActive(time_t t); - void setLabels(tr_quark const* labels, size_t n_labels); + void setLabels(std::vector const& new_labels); /** Return the mime-type (e.g. "audio/x-flac") that matches more of the torrent's content than any other mime-type. */