pub struct TokenizeScratch {
pub xml_buf: Vec<u8>,
pub text_buf: String,
/* private fields */
}Expand description
Scratch buffer pool for tokenization to minimize allocations.
Pre-allocated buffers that can be reused across tokenization operations to avoid repeated allocations in hot paths. This is critical for embedded environments where allocation overhead must be minimized.
Fields§
§xml_buf: Vec<u8>Buffer for XML parsing
text_buf: StringBuffer for text accumulation and normalization
Implementations§
Source§impl TokenizeScratch
impl TokenizeScratch
Sourcepub fn embedded() -> Self
pub fn embedded() -> Self
Create buffers suitable for embedded use (small, bounded).
Uses conservative buffer sizes suitable for constrained environments:
- XML buffer: 4KB
- Text buffer: 8KB
- Element stack: 64 elements
Sourcepub fn desktop() -> Self
pub fn desktop() -> Self
Create buffers for desktop use (larger, more performant).
Uses larger buffer sizes for better performance on desktop:
- XML buffer: 32KB
- Text buffer: 64KB
- Element stack: 64 elements
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear all buffers without deallocating.
This preserves the allocated capacity while resetting the length to zero, allowing the buffers to be reused for subsequent tokenization operations without requiring new allocations.
Sourcepub fn ensure_text_capacity(&mut self, min_cap: usize)
pub fn ensure_text_capacity(&mut self, min_cap: usize)
Ensure text buffer has at least the given capacity.
§Arguments
min_cap- Minimum capacity required
If the current capacity is less than min_cap, the buffer will be
expanded to at least that capacity.