From 8e57d10cb0600b96113007f98e763b7135a928ab Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 23 Nov 2021 12:39:54 +1000 Subject: [PATCH] Stop re-using a drained HashSet --- zebra-network/src/peer_set/set.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/zebra-network/src/peer_set/set.rs b/zebra-network/src/peer_set/set.rs index eb39de58409..ea4fc885b17 100644 --- a/zebra-network/src/peer_set/set.rs +++ b/zebra-network/src/peer_set/set.rs @@ -463,12 +463,12 @@ where } /// Performs P2C on `ready_service_list` to randomly select a less-loaded ready service. - fn select_p2c_peer_from_list(&self, mut ready_service_list: HashSet) -> Option { + fn select_p2c_peer_from_list(&self, ready_service_list: HashSet) -> Option { match ready_service_list.len() { 0 => None, 1 => Some( ready_service_list - .drain() + .into_iter() .next() .expect("just checked there is one service"), ), @@ -480,12 +480,12 @@ where let a = idxs.index(0); let b = idxs.index(1); - let a = ready_service_list - .drain() + let a = *ready_service_list + .iter() .nth(a) .expect("sample returns valid indexes"); - let b = ready_service_list - .drain() + let b = *ready_service_list + .iter() .nth(b) .expect("sample returns valid indexes");