From 1b310db3e5797f24cf367ecf3c0027d64734e83b Mon Sep 17 00:00:00 2001 From: Brooks Date: Thu, 13 Jul 2023 13:51:15 -0400 Subject: [PATCH] Uses while-let (#32479) --- core/src/consensus/heaviest_subtree_fork_choice.rs | 6 ++---- core/src/consensus/tree_diff.rs | 3 +-- core/src/verified_vote_packets.rs | 3 +-- local-cluster/src/cluster_tests.rs | 3 +-- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/core/src/consensus/heaviest_subtree_fork_choice.rs b/core/src/consensus/heaviest_subtree_fork_choice.rs index 592760edbdb0f2..c028b3506e2809 100644 --- a/core/src/consensus/heaviest_subtree_fork_choice.rs +++ b/core/src/consensus/heaviest_subtree_fork_choice.rs @@ -356,8 +356,7 @@ impl HeaviestSubtreeForkChoice { let mut tree_root = None; // Find the subtrees to prune let mut to_visit = vec![self.tree_root]; - while !to_visit.is_empty() { - let cur_slot = to_visit.pop().unwrap(); + while let Some(cur_slot) = to_visit.pop() { if cur_slot == new_root { tree_root = Some(new_root); continue; @@ -532,8 +531,7 @@ impl HeaviestSubtreeForkChoice { let mut split_tree_fork_infos = HashMap::new(); let mut to_visit = vec![*slot_hash_key]; - while !to_visit.is_empty() { - let current_node = to_visit.pop().unwrap(); + while let Some(current_node) = to_visit.pop() { let current_fork_info = self .fork_infos .remove(¤t_node) diff --git a/core/src/consensus/tree_diff.rs b/core/src/consensus/tree_diff.rs index 1a03885c2bd31a..dc6980d625637d 100644 --- a/core/src/consensus/tree_diff.rs +++ b/core/src/consensus/tree_diff.rs @@ -15,8 +15,7 @@ pub trait TreeDiff<'a> { } let mut pending_keys = vec![root1]; let mut reachable_set = HashSet::new(); - while !pending_keys.is_empty() { - let current_key = pending_keys.pop().unwrap(); + while let Some(current_key) = pending_keys.pop() { if current_key == root2 { continue; } diff --git a/core/src/verified_vote_packets.rs b/core/src/verified_vote_packets.rs index 135988011fc3a2..53147e6e007d1a 100644 --- a/core/src/verified_vote_packets.rs +++ b/core/src/verified_vote_packets.rs @@ -112,8 +112,7 @@ impl<'a> Iterator for ValidatorGossipVotesIterator<'a> { fn next(&mut self) -> Option { use SingleValidatorVotes::*; - while !self.vote_account_keys.is_empty() { - let vote_account_key = self.vote_account_keys.pop().unwrap(); + while let Some(vote_account_key) = self.vote_account_keys.pop() { // Get all the gossip votes we've queued up for this validator // that are: // 1) missing from the current leader bank diff --git a/local-cluster/src/cluster_tests.rs b/local-cluster/src/cluster_tests.rs index 6e2f3751034788..7bf0c154113909 100644 --- a/local-cluster/src/cluster_tests.rs +++ b/local-cluster/src/cluster_tests.rs @@ -184,8 +184,7 @@ pub fn verify_ledger_ticks(ledger_path: &Path, ticks_per_slot: usize) { .into_iter() .map(|slot| (slot, 0, last_id)) .collect(); - while !pending_slots.is_empty() { - let (slot, parent_slot, last_id) = pending_slots.pop().unwrap(); + while let Some((slot, parent_slot, last_id)) = pending_slots.pop() { let next_slots = ledger .get_slots_since(&[slot]) .unwrap()