struct ColdSlab {
values: Vec<f64>,
values_mirror: Vec<Value>,
name_to_idx: HashMap<String, usize>,
}Expand description
Indexed slab for cold variables. The bytecode VM resolves cold
names to slab indices at compile time and addresses them directly,
skipping the HashMapContext probe + the String::from allocation
that MilkContext::set would otherwise pay on every store.
Two parallel arrays are kept in sync:
values:Vec<f64>— the VM’s fast path. Reads and writes happen here without going through theValueenum.values_mirror:Vec<Value>— used to back evalexpr’sContext::get_value(name) -> Option<&Value>contract, which requires handing out a reference to aValuewe own.
name_to_idx resolves names on first reference (compile-time for
VM-resolved blocks, runtime for evalexpr-driven set_value calls).
Once interned, a name’s slot index is stable for the life of this
MilkContext.
Fields§
§values: Vec<f64>§values_mirror: Vec<Value>§name_to_idx: HashMap<String, usize>Implementations§
Source§impl ColdSlab
impl ColdSlab
Sourcefn intern(&mut self, name: &str) -> usize
fn intern(&mut self, name: &str) -> usize
Return the slab index for name, allocating a fresh slot
(initialised to 0.0) on first reference.
fn get_idx(&self, idx: usize) -> f64
fn set_idx(&mut self, idx: usize, val: f64)
fn get_by_name(&self, name: &str) -> Option<f64>
fn get_value_by_name(&self, name: &str) -> Option<&Value>
fn set_by_name(&mut self, name: &str, val: f64)
fn set_value_by_name(&mut self, name: &str, value: Value)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ColdSlab
impl RefUnwindSafe for ColdSlab
impl Send for ColdSlab
impl Sync for ColdSlab
impl Unpin for ColdSlab
impl UnwindSafe for ColdSlab
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more