Skip to main content

GraphemePool

Struct GraphemePool 

Source
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

Source

pub fn new() -> Self

Create a new empty grapheme pool.

Source

pub fn with_capacity(capacity: usize) -> Self

Create a pool with pre-allocated capacity.

Source

pub fn len(&self) -> usize

Number of active (non-free) slots.

Source

pub fn is_empty(&self) -> bool

Check if the pool is empty.

Source

pub fn capacity(&self) -> usize

Total capacity (including free slots).

Source

pub fn intern(&mut self, text: &str, width: u8) -> GraphemeId

Intern a grapheme string and return its ID.

If the string is already interned, returns the existing ID and increments the reference count.

§Parameters
  • text: The grapheme cluster string
  • width: Display width (0-127)
§Panics

Panics if width > 127 or if the pool exceeds capacity (16M slots).

Source

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.

Source

pub fn retain(&mut self, id: GraphemeId)

Increment the reference count for a grapheme.

Call this when a cell containing this grapheme is copied.

Source

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.

Source

pub fn refcount(&self, id: GraphemeId) -> u32

Get the reference count for a grapheme.

Returns 0 if the ID is invalid or freed.

Source

pub fn clear(&mut self)

Clear all entries from the pool.

Source

pub fn gc(&mut self, buffers: &[&Buffer])

Garbage collect graphemes not referenced by the given buffers.

This implements a Mark-and-Sweep algorithm:

  1. Reset all internal refcounts to 0.
  2. Scan provided buffers and increment refcounts for referenced graphemes.
  3. 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

Source§

fn clone(&self) -> GraphemePool

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GraphemePool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GraphemePool

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.