pub struct Table {
pub array_ptr: *mut u8,
pub asize: u64,
pub metatable: Option<Gc<Table>>,
/* private fields */
}Expand description
Lua table — hybrid array + hash storage, with optional metatable and weak-mode flags.
Fields§
§array_ptr: *mut u8P11-S5d.I — single backing pointer for the array part. Points
to inline_storage (asize <= INLINE_ASIZE) or slab.as_ptr()
(asize > INLINE_ASIZE). The JIT inline aset reads this with one
load i64, no branch — the choice between inline and slab is
already encoded in the pointer. Initialised in Heap::new_table
AFTER the Table reaches its final heap address (so that
&mut self.inline_storage is the stable heap pointer, not a
stack-local one). Updated by Table::resize.
asize: u64Length of the array part in slots. u64 (rather than usize or
u32) so the JIT can load it with a single load i64.
metatable: Option<Gc<Table>>P11-S5d.K — visibility lifted to pub(crate) so the JIT can
take its field offset at compile time and emit an inline
“metatable.is_none()” guard before the inline aget fast path.
Option<Gc<Table>> is 8 bytes via the NonNull-pointer-opt: 0
⇔ None, non-zero ⇔ Some.
Implementations§
Source§impl Table
impl Table
Sourcepub fn set_metatable(&mut self, mt: Option<Gc<Table>>)
pub fn set_metatable(&mut self, mt: Option<Gc<Table>>)
Install (or clear) this table’s metatable. Does not perform any
__metatable guarding; that belongs in the Vm-level setmetatable.
Sourcepub fn get(&self, key: Value) -> Value
pub fn get(&self, key: Value) -> Value
Raw lookup (no __index metamethod). Returns Value::Nil when
the key is absent. Value::Nil and NaN floats return nil directly.
Sourcepub fn get_str(&self, key: Gc<LuaStr>) -> Value
pub fn get_str(&self, key: Gc<LuaStr>) -> Value
String-keyed variant of Self::get for v1.2 D4 A1 GetField fast
path: the GetField interp arm always has a Gc<LuaStr> key from
Proto.consts. Skips the outer Value match (which would only
take the _ => self.get_hash(k) arm anyway) so the dispatcher
pays one less branch per call. ~5 GetField/iter × 1000 iters/cell
on the Redis-Lua-shape workload — every shaved nanosecond shows
up at the bench level. Counter-validated via
examples/diag_opcode_breakdown.rs.
Sourcepub fn set(
&mut self,
heap: &mut Heap,
key: Value,
val: Value,
) -> Result<(), TableError>
pub fn set( &mut self, heap: &mut Heap, key: Value, val: Value, ) -> Result<(), TableError>
Insert / update (key, val). heap is used to credit any internal
Box growth (rehash) to heap.bytes so the counter stays in sync with
real memory; free_obj subtracts internal_bytes() on the way out.
Sourcepub fn set_int(
&mut self,
heap: &mut Heap,
i: i64,
val: Value,
) -> Result<(), TableError>
pub fn set_int( &mut self, heap: &mut Heap, i: i64, val: Value, ) -> Result<(), TableError>
Integer-keyed variant of Self::set.