From 51cabe99df505d753d9fcc7a383832f81fbf8b6c Mon Sep 17 00:00:00 2001 From: ze0s <43699394+zze0s@users.noreply.github.com> Date: Mon, 20 Jan 2025 17:14:52 +0100 Subject: [PATCH] refactor(setTags): optimize loop Co-authored-by: Chocobo1 --- src/webui/api/torrentscontroller.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index d44bcee24..f611aea27 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -1482,12 +1482,14 @@ void TorrentsController::setTagsAction() const QStringList hashes {params()[u"hashes"_s].split(u'|', Qt::SkipEmptyParts)}; const QStringList tags {params()[u"tags"_s].split(u',', Qt::SkipEmptyParts)}; - const TagSet newTags {tags.begin(), tags.end()}; + TagSet newTags {tags.begin(), tags.end()}; applyToTorrents(hashes, [&newTags](BitTorrent::Torrent *const torrent) { for (const Tag &tag : asConst(torrent->tags())) - if (!newTags.contains(tag)) + { + if (newTags.erase(tag) == 0) torrent->removeTag(tag); + } for (const Tag &tag : newTags) torrent->addTag(tag); });