diagram_core/src/strings.rs#
Source: lib/diagram_core/src/strings.rs
strings -- the document's string table: names, formulas and texts kept once, as Sym
Strings::new() "" is Sym::EMPTY, then the names the crate knows
s.intern("PinX") -> Sym the string's handle (the same text -> the same Sym)
s.get("PinX") -> Option<Sym> without adding it
s.str(sym) -> &str
A drawing with thousands of shapes repeats a few hundred cell names and formulas many times
(THEMEVAL(), GUARD(Width*0.5) ...); each text is kept once and a cell holds four-byte
handles. The table only grows: a Sym stays valid as long as its document, so undo steps can
keep them. A Sym belongs to one document; between documents texts go through str().
The texts come from files, which are untrusted: the index is an ordered map, so no choice of
texts makes a lookup slower than log n comparisons (a hash table with a fixed hash can be
flooded with texts that all fall on one slot).
struct Sym(pub(crate) u32)a text of a document's string table (cell and row names, formulas, values, raw XML)
impl Sym
const EMPTY: Sym = Sym(0)the empty textfn index(self) -> u32the position in the table (0 = the empty text)struct Stringsthe string table of a document
impl Strings
fn new() -> Selfa table with the empty text and the names the crate itself refers tofn intern(&mut self, text: &str) -> Symthe handle oftext, added when it is newfn get(&self, text: &str) -> Option<Sym>the handle oftextwhen the table has itfn str(&self, sym: Sym) -> &strthe text of a handle ("" for a handle of another, larger table)fn len(&self) -> usizethe number of texts in the tablefn is_empty(&self) -> boolwhether the table holds nothing but the empty text and the known names