refactor(setTags): optimize loop

Co-authored-by: Chocobo1 <Chocobo1@users.noreply.github.com>
This commit is contained in:
ze0s 2025-01-20 17:14:52 +01:00 committed by GitHub
commit 51cabe99df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1482,12 +1482,14 @@ void TorrentsController::setTagsAction()
const QStringList hashes {params()[u"hashes"_s].split(u'|', Qt::SkipEmptyParts)}; const QStringList hashes {params()[u"hashes"_s].split(u'|', Qt::SkipEmptyParts)};
const QStringList tags {params()[u"tags"_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) applyToTorrents(hashes, [&newTags](BitTorrent::Torrent *const torrent)
{ {
for (const Tag &tag : asConst(torrent->tags())) for (const Tag &tag : asConst(torrent->tags()))
if (!newTags.contains(tag)) {
if (newTags.erase(tag) == 0)
torrent->removeTag(tag); torrent->removeTag(tag);
}
for (const Tag &tag : newTags) for (const Tag &tag : newTags)
torrent->addTag(tag); torrent->addTag(tag);
}); });