Skip to content

Commit

Permalink
Stop re-using a drained HashSet
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Nov 23, 2021
1 parent 7849ca6 commit 8e57d10
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions zebra-network/src/peer_set/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<D::Key>) -> Option<D::Key> {
fn select_p2c_peer_from_list(&self, ready_service_list: HashSet<D::Key>) -> Option<D::Key> {
match ready_service_list.len() {
0 => None,
1 => Some(
ready_service_list
.drain()
.into_iter()
.next()
.expect("just checked there is one service"),
),
Expand All @@ -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");

Expand Down

0 comments on commit 8e57d10

Please sign in to comment.