diff --git a/src/node_cache.cpp b/src/node_cache.cpp index 386b44ad..a3d3a241 100644 --- a/src/node_cache.cpp +++ b/src/node_cache.cpp @@ -35,21 +35,19 @@ NodeCache::getNode(const InfoHash& id, const sockaddr* sa, socklen_t sa_len, tim std::vector> NodeCache::getCachedNodes(const InfoHash& id, sa_family_t sa_f, size_t total) { - auto c = (sa_f == AF_INET ? cache_4 : cache_6); + const auto& c = (sa_f == AF_INET ? cache_4 : cache_6); auto it_p = c.lower_bound(id), it_n = it_p; std::vector> nodes; nodes.reserve(std::min(c.size(), total)); - decltype(c)::iterator it; + NodeMap::const_iterator it; if (it_p != c.begin()) /* Create 2 separate iterator if we could */ --it_p; - while ( nodes.size() != total - or (it_n == c.end() and it_p == c.end()) ) { - - /* If one of the iterator is at the end, then take the other one + while (nodes.size() < total and (it_n != c.end() or it_p != c.end())) { + /* If one of the iterator is at the end, then take the other one If they are both in middle of somewhere comapre both and take the closest to the id. */ if (it_p == c.end()) it = it_n++;