Add EntityMap::with_capacity.
Create a secondary entity map with space reserved for a known range of entity references. Add dfg.num_ebbs() and dfg.num_insts() methods to provide capacities.
This commit is contained in:
@@ -102,6 +102,21 @@ impl<K, V> EntityMap<K, V>
|
|||||||
where K: EntityRef,
|
where K: EntityRef,
|
||||||
V: Clone + Default
|
V: Clone + Default
|
||||||
{
|
{
|
||||||
|
/// Create a new secondary `EntityMap` that is prepared to hold `n` elements.
|
||||||
|
///
|
||||||
|
/// Use this when the length of the primary map is known:
|
||||||
|
/// ```
|
||||||
|
/// let secondary_map = EntityMap::with_capacity(primary_map.len());
|
||||||
|
/// ```
|
||||||
|
pub fn with_capacity(n: usize) -> Self {
|
||||||
|
let mut map = EntityMap {
|
||||||
|
elems: Vec::with_capacity(n),
|
||||||
|
unused: PhantomData,
|
||||||
|
};
|
||||||
|
map.elems.resize(n, V::default());
|
||||||
|
map
|
||||||
|
}
|
||||||
|
|
||||||
/// Ensure that `k` is a valid key but adding default entries if necesssary.
|
/// Ensure that `k` is a valid key but adding default entries if necesssary.
|
||||||
///
|
///
|
||||||
/// Return a mutable reference to the corresponding entry.
|
/// Return a mutable reference to the corresponding entry.
|
||||||
|
|||||||
@@ -42,6 +42,22 @@ impl DataFlowGraph {
|
|||||||
extended_values: Vec::new(),
|
extended_values: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the total number of instructions created in this function, whether they are currently
|
||||||
|
/// inserted in the layout or not.
|
||||||
|
///
|
||||||
|
/// This is intended for use with `EntityMap::with_capacity`.
|
||||||
|
pub fn num_insts(&self) -> usize {
|
||||||
|
self.insts.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the total number of extended basic blocks created in this function, whether they are
|
||||||
|
/// currently inserted in the layout or not.
|
||||||
|
///
|
||||||
|
/// This is intended for use with `EntityMap::with_capacity`.
|
||||||
|
pub fn num_ebbs(&self) -> usize {
|
||||||
|
self.ebbs.len()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handling values.
|
/// Handling values.
|
||||||
|
|||||||
Reference in New Issue
Block a user