Skip to main content

Module arena

Module arena 

Source
Expand description

An arena for interning strings (global, mutable, single thread only)

Note: works under the assumption of a single threaded, short-lived process, where memory starvation will not be an issue. It would need a hard reset if the same process does multiple conversions, and a different implementation if one needs a thread-local arena.

§Borrow safety

A lend (with and its siblings) holds a shared RefCell borrow of the arena for the closure’s duration, so the buffer it lends from cannot move under it. A string interned while a lend is live cannot grow that buffer: it goes to the overflow page, its own Rc<str> under a symbol at or above OVERFLOW_BASE. One string has one symbol across both tiers until a reset: every intern probes the buffer first, then the page, and only a string neither holds is added (to the buffer outside a lend, to the page under one).

Re-exports§

pub use data::SymHashMap;
pub use data::SymStr;

Modules§

data

Functions§

first_bytes
The first N bytes of sym’s text, if it has as many, for a test by name on a hot path.
get
Probe-only lookup: the symbol for text if it was ever interned, without interning it. For existence-style checks (e.g. install_definition’s "{cs}:locked" gate) a None here proves the key cannot be bound in any state table — and skipping the intern avoids permanently growing the arena with one probe-key twin per defined control sequence (2026-08-23 audit R6).
get_suffixed
get of name with suffix appended, without formatting a string: every definition asks this of its side keys ("{cs}:locked", "{cs}:error@stub"), and almost none of them exists.
join
len
pin
Assign a string into the arena, returning a unique symbol.
pin_char
pin_qname
pin of prefix:local, spelled in a reused buffer rather than a new String: get_node_qname asks it of every element and attribute it names.
pin_static
Assign a static str into the arena, returning a unique symbol.
reset
Free every interned string on this thread, returning the arena to a fresh, empty state.
shrink
reset to a zero-capacity interner, for a thread about to exit (latexml_core::shrink_thread_engine): the arena is a leaked root, so a 2^17-slot interner left in it would outlive the thread.
take_overflow_interns
The number of strings the overflow page took (interned while a lend was live) since the last call: every conversion entry point takes it at its start, and the conversion’s end reports it as a Debug line.
to_string
with
Resolve a symbol and call the closure with a &str reference. The closure may intern (pin(), pin_char(), …): the text is lent under a shared borrow of the arena, so a string new during the lend goes to the overflow page instead of growing (and moving) the buffer the text lives in (string-interner 0.20 buffer.rs:144). An overflow symbol’s lend holds the borrow too, so every lend is one where a reset panics.
with2
with3
with_many