pub struct InternedStringMap { /* private fields */ }Expand description
The short-string intern table, shaped like C-Lua’s stringtable
(lstring.c): power-of-two hash buckets of GcRef<LuaString> chained by
Vec instead of u.hnext. Compared to the previous
HashMap<Box<[u8]>, GcRef<LuaString>>:
- lookup hashes the input bytes ONCE and never allocates (the entry-API
shape boxed the key on every call — rejected experiment
intern-hitpath-borrowed-lookupdocuments why a partial fix loses); - insert reuses the same hash, no second probe;
- bytes are stored once (in the
LuaString), not duplicated in a map key; - dead strings are removed O(dead) by
(hash, identity)pairs collected during the GC mark phase, replacing the O(table·log live) sort + binary-search retain that dominated churn-heavy profiles (concat_chain 20260609T2201Z: intern machinery ~25% of wall).
Implementations§
Source§impl InternedStringMap
impl InternedStringMap
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn find(&self, bytes: &[u8], hash: u32) -> Option<GcRef<LuaString>>
Sourcepub fn insert(&mut self, s: GcRef<LuaString>)
pub fn insert(&mut self, s: GcRef<LuaString>)
C’s luaS_resize growth rule: keep average chain length ~1.
Sourcepub fn remove(&mut self, hash: u32, identity: usize)
pub fn remove(&mut self, hash: u32, identity: usize)
O(dead): removes one entry located by its cached hash + GC identity.
pub fn iter(&self) -> impl Iterator<Item = &GcRef<LuaString>>
pub fn contains_key(&self, bytes: &[u8]) -> bool
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for InternedStringMap
impl !Send for InternedStringMap
impl !Sync for InternedStringMap
impl !UnwindSafe for InternedStringMap
impl Freeze for InternedStringMap
impl Unpin for InternedStringMap
impl UnsafeUnpin for InternedStringMap
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