|
1 | 1 | use rustc_data_structures::captures::Captures; |
| 2 | +use rustc_data_structures::fx::FxHashSet; |
2 | 3 | use rustc_data_structures::graph::dominators::{self, Dominators}; |
3 | 4 | use rustc_data_structures::graph::{self, GraphSuccessors, WithNumNodes, WithStartNode}; |
4 | 5 | use rustc_index::bit_set::BitSet; |
@@ -30,24 +31,16 @@ impl CoverageGraph { |
30 | 31 | // `SwitchInt` to have multiple targets to the same destination `BasicBlock`, so |
31 | 32 | // de-duplication is required. This is done without reordering the successors. |
32 | 33 |
|
33 | | - let mut seen = IndexVec::from_elem(false, &bcbs); |
34 | 34 | let successors = IndexVec::from_fn_n( |
35 | 35 | |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) |
42 | 39 | .into_iter() |
43 | 40 | .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<_>>() |
51 | 44 | }, |
52 | 45 | bcbs.len(), |
53 | 46 | ); |
|
0 commit comments