Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fe6cf34

Browse files
committedMar 4, 2025
Also simplify Preorder's size_hint
1 parent e403654 commit fe6cf34

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed
 

‎compiler/rustc_middle/src/mir/traversal.rs

+5-15
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,13 @@ pub struct Preorder<'a, 'tcx> {
2323
body: &'a Body<'tcx>,
2424
visited: DenseBitSet<BasicBlock>,
2525
worklist: Vec<BasicBlock>,
26-
root_is_start_block: bool,
2726
}
2827

2928
impl<'a, 'tcx> Preorder<'a, 'tcx> {
3029
pub fn new(body: &'a Body<'tcx>, root: BasicBlock) -> Preorder<'a, 'tcx> {
3130
let worklist = vec![root];
3231

33-
Preorder {
34-
body,
35-
visited: DenseBitSet::new_empty(body.basic_blocks.len()),
36-
worklist,
37-
root_is_start_block: root == START_BLOCK,
38-
}
32+
Preorder { body, visited: DenseBitSet::new_empty(body.basic_blocks.len()), worklist }
3933
}
4034
}
4135

@@ -71,15 +65,11 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
7165
}
7266

7367
fn size_hint(&self) -> (usize, Option<usize>) {
74-
// All the blocks, minus the number of blocks we've visited.
75-
let upper = self.body.basic_blocks.len() - self.visited.count();
68+
// The worklist might be only things already visited.
69+
let lower = 0;
7670

77-
let lower = if self.root_is_start_block {
78-
// We will visit all remaining blocks exactly once.
79-
upper
80-
} else {
81-
self.worklist.len()
82-
};
71+
// This is extremely loose, but it's not worth a popcnt loop to do better.
72+
let upper = self.body.basic_blocks.len();
8373

8474
(lower, Some(upper))
8575
}

0 commit comments

Comments
 (0)
Failed to load comments.