diff options
| author | Zalathar <Zalathar@users.noreply.github.com> | 2024-01-01 22:59:47 +1100 |
|---|---|---|
| committer | Zalathar <Zalathar@users.noreply.github.com> | 2024-01-14 12:11:26 +1100 |
| commit | 5eae9452b6762a1347a3dec4f40c8ddc7789a868 (patch) | |
| tree | 158eea902866c4847e95145d0fec44c6a1b187bb | |
| parent | 867950f8c6f4a11e388e3e3e75cdf5344e95e4e8 (diff) | |
| download | rust-5eae9452b6762a1347a3dec4f40c8ddc7789a868.tar.gz rust-5eae9452b6762a1347a3dec4f40c8ddc7789a868.zip | |
coverage: Simplify computing successors in the BCB graph
| -rw-r--r-- | compiler/rustc_mir_transform/src/coverage/graph.rs | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/graph.rs b/compiler/rustc_mir_transform/src/coverage/graph.rs index 9a3605b7a6a..c6badbe78a4 100644 --- a/compiler/rustc_mir_transform/src/coverage/graph.rs +++ b/compiler/rustc_mir_transform/src/coverage/graph.rs @@ -1,4 +1,5 @@ use rustc_data_structures::captures::Captures; +use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::graph::dominators::{self, Dominators}; use rustc_data_structures::graph::{self, GraphSuccessors, WithNumNodes, WithStartNode}; use rustc_index::bit_set::BitSet; @@ -30,24 +31,16 @@ impl CoverageGraph { // `SwitchInt` to have multiple targets to the same destination `BasicBlock`, so // de-duplication is required. This is done without reordering the successors. - let mut seen = IndexVec::from_elem(false, &bcbs); let successors = IndexVec::from_fn_n( |bcb| { - for b in seen.iter_mut() { - *b = false; - } - let bcb_data = &bcbs[bcb]; - let mut bcb_successors = Vec::new(); - for successor in bcb_filtered_successors(mir_body[bcb_data.last_bb()].terminator()) + let mut seen_bcbs = FxHashSet::default(); + let terminator = mir_body[bcbs[bcb].last_bb()].terminator(); + bcb_filtered_successors(terminator) .into_iter() .filter_map(|successor_bb| bb_to_bcb[successor_bb]) - { - if !seen[successor] { - seen[successor] = true; - bcb_successors.push(successor); - } - } - bcb_successors + // Remove duplicate successor BCBs, keeping only the first. + .filter(|&successor_bcb| seen_bcbs.insert(successor_bcb)) + .collect::<Vec<_>>() }, bcbs.len(), ); |
