keep labels in order added, rather than alphabetically (#3271)

This commit is contained in:
Viacheslav Chimishuk 2022-06-17 01:08:42 +03:00 committed by GitHub
parent 06e5767234
commit 0397176c10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 8 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -11,7 +11,6 @@
#include <csignal> /* signal() */
#include <ctime>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <string_view>
@ -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<tr_quark> const& new_labels)
{
auto const lock = unique_lock();
auto const sorted_unique = std::set<tr_quark>{ 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();
}

View File

@ -581,7 +581,7 @@ public:
void setDateActive(time_t t);
void setLabels(tr_quark const* labels, size_t n_labels);
void setLabels(std::vector<tr_quark> 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. */