udp: swarm: extract_response_peers: improve docs, add .copied() to iters

This commit is contained in:
Joakim Frostegård 2024-02-11 01:02:16 +01:00
parent f455e58251
commit 61bc4f0d9d

View file

@ -570,11 +570,10 @@ impl<I: Ip> LargePeerMap<I> {
/// Extract response peers /// Extract response peers
/// ///
/// If there are more peers in map than `max_num_peers_to_take`, do a random /// If there are more peers in map than `max_num_peers_to_take`, do a
/// selection of peers from first and second halves of map in order to avoid /// random selection of peers from first and second halves of map in
/// returning too homogeneous peers. /// order to avoid returning too homogeneous peers. This is a lot more
/// /// cache-friendly than doing a fully random selection.
/// Does NOT filter out announcing peer.
fn extract_response_peers( fn extract_response_peers(
&self, &self,
rng: &mut impl Rng, rng: &mut impl Rng,
@ -605,10 +604,10 @@ impl<I: Ip> LargePeerMap<I> {
let mut peers = Vec::with_capacity(max_num_peers_to_take); 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) { 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) { if let Some(slice) = self.peers.get_range(offset_half_two..end_half_two) {
peers.extend(slice.keys()); peers.extend(slice.keys().copied());
} }
peers peers