From a6c7aef6c119fd010a049a1482401c4997541e47 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Thu, 7 Nov 2024 09:40:33 +0300 Subject: [PATCH] Optimize checking for outdated tracker endpoints PR #21768. --- src/base/bittorrent/torrentimpl.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 5ebc5919c..7458814c4 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -115,16 +115,6 @@ namespace trackerEntryStatus.tier = nativeEntry.tier; - // remove outdated endpoints - trackerEntryStatus.endpoints.removeIf([&nativeEntry](const QHash, TrackerEndpointStatus>::iterator &iter) - { - return std::none_of(nativeEntry.endpoints.cbegin(), nativeEntry.endpoints.cend() - , [&endpointName = std::get<0>(iter.key())](const auto &existingEndpoint) - { - return (endpointName == toString(existingEndpoint.local_endpoint)); - }); - }); - const auto numEndpoints = static_cast(nativeEntry.endpoints.size()) * btProtocols.size(); int numUpdating = 0; @@ -207,6 +197,19 @@ namespace } } + if (trackerEntryStatus.endpoints.size() > numEndpoints) + { + // remove outdated endpoints + trackerEntryStatus.endpoints.removeIf([&nativeEntry](const QHash, TrackerEndpointStatus>::iterator &iter) + { + return std::none_of(nativeEntry.endpoints.cbegin(), nativeEntry.endpoints.cend() + , [&endpointName = std::get<0>(iter.key())](const auto &existingEndpoint) + { + return (endpointName == toString(existingEndpoint.local_endpoint)); + }); + }); + } + if (numEndpoints > 0) { if (numUpdating > 0)