Improved DFG API (#95)
* Improved DFG API with swap_remove_ebb_args and append_inst_arg * Implemented EntityList::swap_remove And used it for dfg::swap_remove_ebb_arg
This commit is contained in:
committed by
Jakob Stoklund Olesen
parent
81284dbd93
commit
2f33848fcd
@@ -416,7 +416,7 @@ impl<T: EntityRef> EntityList<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes the element at position `index` from the list.
|
||||
/// Removes the element at position `index` from the list. Potentially linear complexity.
|
||||
pub fn remove(&mut self, index: usize, pool: &mut ListPool<T>) {
|
||||
let len;
|
||||
{
|
||||
@@ -448,6 +448,22 @@ impl<T: EntityRef> EntityList<T> {
|
||||
pool.data[block] = T::new(len - 1);
|
||||
}
|
||||
|
||||
/// Removes the element at `index` in constant time by switching it with the last element of
|
||||
/// the list.
|
||||
pub fn swap_remove(&mut self, index: usize, pool: &mut ListPool<T>) {
|
||||
let len = self.len(pool);
|
||||
assert!(index < len);
|
||||
if index == len - 1 {
|
||||
self.remove(index, pool);
|
||||
} else {
|
||||
{
|
||||
let seq = self.as_mut_slice(pool);
|
||||
seq.swap(index, len - 1);
|
||||
}
|
||||
self.remove(len - 1, pool);
|
||||
}
|
||||
}
|
||||
|
||||
/// Grow the list by inserting `count` elements at `index`.
|
||||
///
|
||||
/// The new elements are not initialized, they will contain whatever happened to be in memory.
|
||||
|
||||
Reference in New Issue
Block a user