Skip to main content

Module grapheme_pool

Module grapheme_pool 

Source
Expand description

Grapheme pooling and interning.

The GraphemePool stores complex grapheme clusters (emoji, ZWJ sequences, etc.) that don’t fit in CellContent’s 4-byte inline storage. It provides:

  • Compact GraphemeId references (4 bytes) instead of heap strings per cell
  • Reference counting for automatic cleanup
  • Deduplication via hash lookup
  • Slot reuse via free list

Β§When to Use

Most cells use simple characters that fit inline in CellContent. The pool is only needed for:

  • Multi-codepoint emoji (πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦, πŸ§‘πŸ½β€πŸ’», etc.)
  • ZWJ sequences
  • Complex combining character sequences

Β§Usage

use ftui_render::grapheme_pool::GraphemePool;

let mut pool = GraphemePool::new();

// Intern a grapheme
let id = pool.intern("πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦", 2); // Family emoji, width 2

// Look it up
assert_eq!(pool.get(id), Some("πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦"));
assert_eq!(id.width(), 2);

// Increment reference count when copied to another cell
pool.retain(id);

// Release when cell is overwritten
pool.release(id);
pool.release(id);

// After all references released, slot is freed
assert_eq!(pool.get(id), None);

StructsΒ§

GraphemePool
A reference-counted pool for complex grapheme clusters.