pub fn trim(
arena: &mut MorselArena,
ends: StrTrim,
set: &TrimSet,
v: &ValueVector,
) -> Result<ValueVector>Expand description
Evaluate ends(v, set) into a new flat string vector.
This is the string kernel that fills no buffer. What a trim answers is a part of what it was handed, and a part of a string is bytes that are already somewhere, so a flat argument’s answers are views back into the argument’s own buffers and the answer vector holds the same buffers rather than a copy of them. A chunk of two thousand trimmed strings costs two thousand views and not one byte more.
That is a saving in memory rather than in time. The walk still tests the set once for every character it takes off, which on the bench’s fifteen byte strings costs about what the fold’s copy of the same string costs, so the two run level there.
A dictionary is the one shape that cannot do that, since the entries of a table are not bytes a view can name, so the table’s answers are written out once an entry and the rows gather over them. That is still a table’s worth of copying rather than a chunk’s.