Skip to content

Commit cf4da49

Browse files
committed
coverage: Simplify computing successors in the BCB graph
1 parent f27ba3c commit cf4da49

File tree

1 file changed

+7
-14
lines changed
  • compiler/rustc_mir_transform/src/coverage

1 file changed

+7
-14
lines changed

compiler/rustc_mir_transform/src/coverage/graph.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_data_structures::captures::Captures;
2+
use rustc_data_structures::fx::FxHashSet;
23
use rustc_data_structures::graph::dominators::{self, Dominators};
34
use rustc_data_structures::graph::{self, GraphSuccessors, WithNumNodes, WithStartNode};
45
use rustc_index::bit_set::BitSet;
@@ -30,24 +31,16 @@ impl CoverageGraph {
3031
// `SwitchInt` to have multiple targets to the same destination `BasicBlock`, so
3132
// de-duplication is required. This is done without reordering the successors.
3233

33-
let mut seen = IndexVec::from_elem(false, &bcbs);
3434
let successors = IndexVec::from_fn_n(
3535
|bcb| {
36-
for b in seen.iter_mut() {
37-
*b = false;
38-
}
39-
let bcb_data = &bcbs[bcb];
40-
let mut bcb_successors = Vec::new();
41-
for successor in bcb_filtered_successors(mir_body[bcb_data.last_bb()].terminator())
36+
let mut seen_bcbs = FxHashSet::default();
37+
let terminator = mir_body[bcbs[bcb].last_bb()].terminator();
38+
bcb_filtered_successors(terminator)
4239
.into_iter()
4340
.filter_map(|successor_bb| bb_to_bcb[successor_bb])
44-
{
45-
if !seen[successor] {
46-
seen[successor] = true;
47-
bcb_successors.push(successor);
48-
}
49-
}
50-
bcb_successors
41+
// Remove duplicate successor BCBs, keeping only the first.
42+
.filter(|&successor_bcb| seen_bcbs.insert(successor_bcb))
43+
.collect::<Vec<_>>()
5144
},
5245
bcbs.len(),
5346
);

0 commit comments

Comments
 (0)