From 61bc4f0d9d6230abe4c8c437bd21b6b4cdfe8984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sun, 11 Feb 2024 01:02:16 +0100 Subject: [PATCH] udp: swarm: extract_response_peers: improve docs, add .copied() to iters --- crates/udp/src/swarm.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/udp/src/swarm.rs b/crates/udp/src/swarm.rs index c9523a2..2d422f9 100644 --- a/crates/udp/src/swarm.rs +++ b/crates/udp/src/swarm.rs @@ -570,11 +570,10 @@ impl LargePeerMap { /// Extract response peers /// - /// If there are more peers in map than `max_num_peers_to_take`, do a random - /// selection of peers from first and second halves of map in order to avoid - /// returning too homogeneous peers. - /// - /// Does NOT filter out announcing peer. + /// If there are more peers in map than `max_num_peers_to_take`, do a + /// random selection of peers from first and second halves of map in + /// order to avoid returning too homogeneous peers. This is a lot more + /// cache-friendly than doing a fully random selection. fn extract_response_peers( &self, rng: &mut impl Rng, @@ -605,10 +604,10 @@ impl LargePeerMap { let mut peers = Vec::with_capacity(max_num_peers_to_take); if let Some(slice) = self.peers.get_range(offset_half_one..end_half_one) { - peers.extend(slice.keys()); + peers.extend(slice.keys().copied()); } if let Some(slice) = self.peers.get_range(offset_half_two..end_half_two) { - peers.extend(slice.keys()); + peers.extend(slice.keys().copied()); } peers