Function alloc_iter2

Source
fn alloc_iter2<T>(iter: impl Iterator<Item = T>) -> &'static [T]
Expand description

Allocates an iterator’s items into a bump-allocated slice.

This function leverages a thread-local bump arena to efficiently allocate memory for storing the items produced by the provided iterator. It uses collect_in to gather the iterator’s elements within the context of the arena’s bump allocation, ensuring the allocation remains valid for the program’s lifetime. A reference to the bump allocator is obtained through unsafe pointer dereferencing, and the iterator’s elements are collected into a bump vector (BVec). This vector is then converted into a static reference to a slice stored in the arena memory, offering a performance advantage by reducing heap allocation overhead.