Avoid unnecessary reallocations in domtree::with_function() (#1011)
This commit is contained in:
@@ -226,7 +226,13 @@ impl DominatorTree {
|
||||
|
||||
/// Allocate and compute a dominator tree.
|
||||
pub fn with_function(func: &Function, cfg: &ControlFlowGraph) -> Self {
|
||||
let mut domtree = Self::new();
|
||||
let ebb_capacity = func.layout.ebb_capacity();
|
||||
let mut domtree = Self {
|
||||
nodes: SecondaryMap::with_capacity(ebb_capacity),
|
||||
postorder: Vec::with_capacity(ebb_capacity),
|
||||
stack: Vec::new(),
|
||||
valid: false,
|
||||
};
|
||||
domtree.compute(func, cfg);
|
||||
domtree
|
||||
}
|
||||
|
||||
@@ -60,6 +60,11 @@ impl Layout {
|
||||
self.first_ebb = None;
|
||||
self.last_ebb = None;
|
||||
}
|
||||
|
||||
/// Returns the capacity of the `EbbData` map.
|
||||
pub fn ebb_capacity(&self) -> usize {
|
||||
self.ebbs.capacity()
|
||||
}
|
||||
}
|
||||
|
||||
/// Sequence numbers.
|
||||
|
||||
Reference in New Issue
Block a user