Skip to content

Commit 5bae3ad

Browse files
committed
Calculate predecessor count directly
Avoid allocating a vector of small vectors merely to determine how many predecessors each basic block has. Additionally use u8 and saturating operations. The pass only needs to distinguish between [0..1] and [2..].
1 parent 508b803 commit 5bae3ad

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

compiler/rustc_mir_transform/src/add_call_guards.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ pub(super) use self::AddCallGuards::*;
3232

3333
impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
3434
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
35-
let mut pred_count: IndexVec<_, _> =
36-
body.basic_blocks.predecessors().iter().map(|ps| ps.len()).collect();
35+
let mut pred_count = IndexVec::from_elem(0u8, &body.basic_blocks);
36+
for (_, data) in body.basic_blocks.iter_enumerated() {
37+
for succ in data.terminator().successors() {
38+
pred_count[succ] = pred_count[succ].saturating_add(1);
39+
}
40+
}
3741

3842
// We need a place to store the new blocks generated
3943
let mut new_blocks = Vec::new();

0 commit comments

Comments
 (0)