Add take_value_list and put_value_list methods.
Any code that needs to manipulate a variable argument list on an instruction will need to remove the instruction's value list first, change the list, and then put it back on the instruction. This is required to avoid fighting the borrow checker over mutable locks on the DataFlowGraph and its value list pool. Add a generated InstructionData::take_value_list() method which lifts out and existing value list and returns it, levaing an empty list in its place, like Option::take() does it. Add a generated InstructionData::put_value_list() which puts it back, verifying that no existing value list is overwritten.
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
//! reserved for the empty list which isn't allocated in the vector.
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
|
||||
use entity_map::EntityRef;
|
||||
|
||||
@@ -273,6 +274,13 @@ impl<T: EntityRef> EntityList<T> {
|
||||
self.index = 0;
|
||||
}
|
||||
|
||||
/// Take all elements from this list and return them as a new list. Leave this list empty.
|
||||
///
|
||||
/// This is the equivalent of `Option::take()`.
|
||||
pub fn take(&mut self) -> EntityList<T> {
|
||||
mem::replace(self, Default::default())
|
||||
}
|
||||
|
||||
/// Appends an element to the back of the list.
|
||||
pub fn push(&mut self, element: T, pool: &mut ListPool<T>) {
|
||||
let idx = self.index as usize;
|
||||
|
||||
Reference in New Issue
Block a user