3 ms·
TBF you could do it in most languages which do have iteration abstraction. However assuming trying to keep to 0-alloc odds are good you'd probably just be tell
by masklinn 3y ago
TBF you could do it in most languages which do have iteration abstraction.
However assuming trying to keep to 0-alloc odds are good you'd probably just be telling the user to git gud as the slices would become nonsensical on every refill of the buffer.
- burntsushi 3y agoYes, 0-alloc and minimal copying is a key constraint here. :-) If you take that away, then there's no real problem here.
- masklinn 3y agoI could easily imagine trying to do it because I can rather than because I actually need to. Also because of the missing middle: in Go (or Java, or C#, or even python) you could hand out slices to a large buffer, but discard the buffer rather than refill it in place, relying on the GC to clean things up (and possibly give you the same buffer on the next allocation). So you get an efficiency middle ground where you allocate more than strictly necessary but not for every line, and maintain correctness. In Rust that’d require some sort of Rc projection which I’m not sure even exists?