pub struct StrBuilder { /* private fields */ }Expand description
Where a kernel puts the bytes of the strings it makes.
A kernel that answers a number writes into a register the arena already sized for it. A kernel that answers a string has no such room, because how many bytes a chunk of answers comes to is not known until the answers are made, so the bytes go here instead and the vector’s views point back into them. Short answers never reach the buffer at all, a view of twelve bytes or fewer carrying its own payload, so a column of words costs one vector and nothing else.
The whole chunk shares one buffer, which is one allocation for a call rather than one per row, and the views hold offsets rather than pointers so the buffer may grow underneath them.
Implementations§
Source§impl StrBuilder
impl StrBuilder
pub fn new() -> Self
Sourcepub fn with_capacity(bytes: usize) -> Self
pub fn with_capacity(bytes: usize) -> Self
Room for the long answers of a chunk, when the caller can say what that comes to. An answer no longer than what it was made from is the common case, so the input’s byte count is the usual argument and the usual outcome is that the buffer never grows.
Sourcepub fn push_with(&mut self, len: usize, fill: impl FnOnce(&mut [u8])) -> StrView
pub fn push_with(&mut self, len: usize, fill: impl FnOnce(&mut [u8])) -> StrView
Room for a string of len bytes, filled by fill, answered as
the view that reads it back.
The caller writes into the answer rather than handing one over, so a fold or a trim costs no working string of its own.
Sourcepub fn finish(self) -> StrBuffers
pub fn finish(self) -> StrBuffers
The buffers the views this handed out read through. A chunk whose answers were all short leaves no buffer behind.