pub struct StringArena { /* private fields */ }Expand description
Bump allocator backing arena-owned AzString instances.
Every AzString returned by StringArena::intern holds a cloned
Arc to this arena; the backing bytes stay alive until the last
such AzString (and the arena handle itself) is dropped.
Intended use: create one arena per XML/HTML parse pass, intern all
tag names / attribute values / text content through it, then drop the
handle. The AzStrings embedded in the resulting StyledDom keep the
arena alive for as long as they need the bytes.
Implementations§
Source§impl StringArena
impl StringArena
Sourcepub const CHUNK_SIZE: usize
pub const CHUNK_SIZE: usize
Size of a freshly allocated chunk. Large enough that a typical DOM parse fits in 1-2 chunks, small enough to not over-allocate for small documents.
pub fn new() -> Self
Sourcepub fn intern(&mut self, s: &str) -> AzString
pub fn intern(&mut self, s: &str) -> AzString
Intern s into the arena and return an AzString whose backing
bytes live inside the arena. The returned AzString owns a cloned
Arc reference; dropping it decrements the refcount, and the
arena frees its chunks when the final reference is released.
§Panics
Panics if the arena’s internal chunk list is unexpectedly empty when appending a non-oversized string (an invariant violation that cannot occur through the public API, since a chunk is allocated on demand).