pub struct SyntaxArena { /* private fields */ }Expand description
A high-performance bump allocator optimized for AST nodes.
The arena works by “bumping” a pointer within a pre-allocated chunk of memory. When a chunk is exhausted, a new one is requested from the thread-local pool or the global allocator.
Implementations§
Source§impl SyntaxArena
impl SyntaxArena
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Creates a new empty arena.
Initial pointers are set to dangling. The first allocation will trigger a chunk allocation.
Sourcepub fn alloc_slice_copy<T: Copy>(&self, slice: &[T]) -> &mut [T]
pub fn alloc_slice_copy<T: Copy>(&self, slice: &[T]) -> &mut [T]
Allocates a slice in the arena and copies the contents of slice into it.
This is useful for storing strings or other contiguous data in the arena.
§Safety
Same as alloc, T must be Copy (and thus POD).
Sourcepub fn alloc_slice_fill_iter<T, I>(&self, count: usize, iter: I) -> &mut [T]where
I: IntoIterator<Item = T>,
pub fn alloc_slice_fill_iter<T, I>(&self, count: usize, iter: I) -> &mut [T]where
I: IntoIterator<Item = T>,
Allocates a slice in the arena and fills it using an iterator.
This is more efficient than collecting into a temporary Vec and then copying,
as it writes directly into the arena memory.
§Safety
The iterator must yield exactly count items. If it yields fewer, the remaining
memory will be uninitialized (UB if accessed). If it yields more, the extra
items are ignored. T must be POD.