toString refactor in druntime
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Thu Oct 30 08:32:29 PDT 2014
On 10/29/14 6:03 AM, Kagamin wrote:
> struct Sink
> {
> char[] buff;
> void delegate(in char[]) sink;
>
> void write(in char[] s)
> {
> auto len=min(s.length,buff.length);
> buff[0..len]=s[0..len];
> buff=buff[len..$];
> const s1=s[len..$];
> if(s1.length)sink(s1);
> }
> }
>
> override void toString(ref Sink sink) const
> {
> value.toString(sink);
> sink.write("[");
> len.toString(sink);
> sink.write("]");
> }
This would require sink to write the buffer before it's first call,
since you don't track that.
Wouldn't it be better to track the "used" length in buff directly so
write can handle that?
Not a bad idea, BTW.
-Steve
More information about the Digitalmars-d
mailing list