Filter out duplicate trackers when replacing

PR #19656.
This commit is contained in:
Vladimir Golovnev 2023-09-29 07:33:19 +03:00
parent 4f3dbf7f59
commit a84259dd1a

View file

@ -600,6 +600,9 @@ void TorrentImpl::replaceTrackers(QVector<TrackerEntry> trackers)
{
// TODO: use std::erase_if() in C++20
trackers.erase(std::remove_if(trackers.begin(), trackers.end(), [](const TrackerEntry &entry) { return entry.url.isEmpty(); }), trackers.end());
// Filter out duplicate trackers
const auto uniqueTrackers = QSet<TrackerEntry>(trackers.cbegin(), trackers.cend());
trackers = QVector<TrackerEntry>(uniqueTrackers.cbegin(), uniqueTrackers.cend());
std::sort(trackers.begin(), trackers.end()
, [](const TrackerEntry &lhs, const TrackerEntry &rhs) { return lhs.tier < rhs.tier; });