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§
Functions§
- first_
bytes - The first
Nbytes ofsym’s text, if it has as many, for a test by name on a hot path. - get
- Probe-only lookup: the symbol for
textif it was ever interned, without interning it. For existence-style checks (e.g.install_definition’s"{cs}:locked"gate) aNonehere 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 getofnamewithsuffixappended, 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 pinofprefix:local, spelled in a reused buffer rather than a newString:get_node_qnameasks 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
resetto 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
&strreference. 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.20buffer.rs:144). An overflow symbol’s lend holds the borrow too, so every lend is one where aresetpanics. - with2
- with3
- with_
many