pub struct GraphemePool { /* private fields */ }Expand description
A reference-counted pool for complex grapheme clusters.
Stores multi-codepoint strings and returns compact GraphemeId references.
Implementations§
Source§impl GraphemePool
impl GraphemePool
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a pool with pre-allocated capacity.
Sourcepub fn intern(&mut self, text: &str, width: u8) -> GraphemeId
pub fn intern(&mut self, text: &str, width: u8) -> GraphemeId
Sourcepub fn get(&self, id: GraphemeId) -> Option<&str>
pub fn get(&self, id: GraphemeId) -> Option<&str>
Get the string for a grapheme ID.
Returns None if the ID is invalid or has been freed.
Sourcepub fn retain(&mut self, id: GraphemeId)
pub fn retain(&mut self, id: GraphemeId)
Increment the reference count for a grapheme.
Call this when a cell containing this grapheme is copied.
Sourcepub fn release(&mut self, id: GraphemeId)
pub fn release(&mut self, id: GraphemeId)
Decrement the reference count for a grapheme.
Call this when a cell containing this grapheme is overwritten or freed. When the reference count reaches zero, the slot is freed for reuse.
Sourcepub fn refcount(&self, id: GraphemeId) -> u32
pub fn refcount(&self, id: GraphemeId) -> u32
Get the reference count for a grapheme.
Returns 0 if the ID is invalid or freed.
Sourcepub fn gc(&mut self, buffers: &[&Buffer])
pub fn gc(&mut self, buffers: &[&Buffer])
Garbage collect graphemes not referenced by the given buffers.
This implements a Mark-and-Sweep algorithm:
- Reset all internal refcounts to 0.
- Scan provided buffers and increment refcounts for referenced graphemes.
- Free any slots that remain with refcount 0.
This should be called periodically (e.g. every N frames) passing the current front and back buffers to prevent memory leaks in long-running apps.
Trait Implementations§
Source§impl Clone for GraphemePool
impl Clone for GraphemePool
Source§fn clone(&self) -> GraphemePool
fn clone(&self) -> GraphemePool
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more