On 10/30/14 11:54 AM, Kagamin wrote:
On Thursday, 30 October 2014 at 15:32:30 UTC, Steven Schveighoffer wrote:
This would require sink to write the buffer before it's first call,
since you don't track that.
That's delegated to the sink delegate.
Keep in mind, sink delegate is not a singly implemented function, it's
implemented wherever the output is done. So it's a lot of boilerplate to
copy around.
Wouldn't it be better to track the "used" length in buff directly so
write can handle that?
The used length is tracked by shrinking the buff. This only shows the
callee's perspective.
No, what I mean is:
struct Sink
{
char[] buff;
uint used; // buff[used..$] is what your buff used to be.
void delegate(in char[]) sink;
...
}
This way, when write finds it runs out of space, first thing it does is
sink the buff, then starts sinking the rest. In fact, you can just keep
using buff once you sink it, to avoid future "extra calls" to sink.
Note, that this can be implemented right on top of the existing sink
mechanism.
-Steve