Skip to main content

Table

Struct Table 

Source
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 u8

P11-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: u64

Length 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

Source

pub fn metatable(&self) -> Option<Gc<Table>>

This table’s metatable, if any.

Source

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.

Source

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.

Source

pub fn get_int(&self, i: i64) -> Value

Integer-keyed variant of Self::get.

Source

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.

Source

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.

Source

pub fn set_int( &mut self, heap: &mut Heap, i: i64, val: Value, ) -> Result<(), TableError>

Integer-keyed variant of Self::set.

Source

pub fn len(&self) -> i64

A border: n where t[n] is non-nil and t[n+1] is nil (PUC luaH_getn). This is Lua # semantics, not a container size — an is_empty counterpart would be meaningless.

Source

pub fn next(&self, key: Value) -> Result<Option<(Value, Value)>, TableError>

Lua next: iterate array part then hash part.

Source§

impl Table

Source

pub fn ensure_array(&mut self, heap: &mut Heap, n: usize)

Preallocate the array part (table.create); existing contents are preserved.

Source§

impl Table

Source

pub fn ensure_hash(&mut self, heap: &mut Heap, n: usize)

Preallocate hash-part capacity (table.create’s second size).

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.