Also simplify Preorder
's size_hint
This commit is contained in:
parent
e403654c8b
commit
fe6cf34147
1 changed files with 5 additions and 15 deletions
|
@ -23,19 +23,13 @@ pub struct Preorder<'a, 'tcx> {
|
||||||
body: &'a Body<'tcx>,
|
body: &'a Body<'tcx>,
|
||||||
visited: DenseBitSet<BasicBlock>,
|
visited: DenseBitSet<BasicBlock>,
|
||||||
worklist: Vec<BasicBlock>,
|
worklist: Vec<BasicBlock>,
|
||||||
root_is_start_block: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> Preorder<'a, 'tcx> {
|
impl<'a, 'tcx> Preorder<'a, 'tcx> {
|
||||||
pub fn new(body: &'a Body<'tcx>, root: BasicBlock) -> Preorder<'a, 'tcx> {
|
pub fn new(body: &'a Body<'tcx>, root: BasicBlock) -> Preorder<'a, 'tcx> {
|
||||||
let worklist = vec![root];
|
let worklist = vec![root];
|
||||||
|
|
||||||
Preorder {
|
Preorder { body, visited: DenseBitSet::new_empty(body.basic_blocks.len()), worklist }
|
||||||
body,
|
|
||||||
visited: DenseBitSet::new_empty(body.basic_blocks.len()),
|
|
||||||
worklist,
|
|
||||||
root_is_start_block: root == START_BLOCK,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,15 +65,11 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
// All the blocks, minus the number of blocks we've visited.
|
// The worklist might be only things already visited.
|
||||||
let upper = self.body.basic_blocks.len() - self.visited.count();
|
let lower = 0;
|
||||||
|
|
||||||
let lower = if self.root_is_start_block {
|
// This is extremely loose, but it's not worth a popcnt loop to do better.
|
||||||
// We will visit all remaining blocks exactly once.
|
let upper = self.body.basic_blocks.len();
|
||||||
upper
|
|
||||||
} else {
|
|
||||||
self.worklist.len()
|
|
||||||
};
|
|
||||||
|
|
||||||
(lower, Some(upper))
|
(lower, Some(upper))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue