From 35cfc6b5d3d7e2b67b7205d41959b28d22dbbca5 Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Fri, 23 Sep 2016 07:30:36 -0700 Subject: [PATCH] shrink peers vectors with too much excess capacity --- src/kademlia/dht_storage.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/kademlia/dht_storage.cpp b/src/kademlia/dht_storage.cpp index c09ea4df1..51a09df55 100644 --- a/src/kademlia/dht_storage.cpp +++ b/src/kademlia/dht_storage.cpp @@ -525,6 +525,9 @@ namespace m_counters.peers -= std::distance(new_end, peers.end()); peers.erase(new_end, peers.end()); + // if we're using less than 1/4 of the capacity free up the excess + if (!peers.empty() && peers.capacity() / peers.size() >= 4u) + peers.shrink_to_fit(); } }; }