diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2025-03-03 21:07:55 -0800 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2025-03-03 21:07:55 -0800 |
| commit | fe6cf341479c91ef90d8c809aea70193ed42036a (patch) | |
| tree | d55857dea703da8520716b787aa78beca7a82479 /compiler | |
| parent | e403654c8b49f7bf62e551c2dc5aaaca9ba71d76 (diff) | |
| download | rust-fe6cf341479c91ef90d8c809aea70193ed42036a.tar.gz rust-fe6cf341479c91ef90d8c809aea70193ed42036a.zip | |
Also simplify `Preorder`'s `size_hint`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_middle/src/mir/traversal.rs | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/compiler/rustc_middle/src/mir/traversal.rs b/compiler/rustc_middle/src/mir/traversal.rs index 5fb3c648d5a..9308570d89d 100644 --- a/compiler/rustc_middle/src/mir/traversal.rs +++ b/compiler/rustc_middle/src/mir/traversal.rs @@ -23,19 +23,13 @@ pub struct Preorder<'a, 'tcx> { body: &'a Body<'tcx>, visited: DenseBitSet<BasicBlock>, worklist: Vec<BasicBlock>, - root_is_start_block: bool, } impl<'a, 'tcx> Preorder<'a, 'tcx> { pub fn new(body: &'a Body<'tcx>, root: BasicBlock) -> Preorder<'a, 'tcx> { let worklist = vec![root]; - Preorder { - body, - visited: DenseBitSet::new_empty(body.basic_blocks.len()), - worklist, - root_is_start_block: root == START_BLOCK, - } + Preorder { body, visited: DenseBitSet::new_empty(body.basic_blocks.len()), worklist } } } @@ -71,15 +65,11 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> { } fn size_hint(&self) -> (usize, Option<usize>) { - // All the blocks, minus the number of blocks we've visited. - let upper = self.body.basic_blocks.len() - self.visited.count(); + // The worklist might be only things already visited. + let lower = 0; - let lower = if self.root_is_start_block { - // We will visit all remaining blocks exactly once. - upper - } else { - self.worklist.len() - }; + // This is extremely loose, but it's not worth a popcnt loop to do better. + let upper = self.body.basic_blocks.len(); (lower, Some(upper)) } |
