Phobos for Review: std.buffer.scopebuffer

Brad Anderson eco at gnuk.net
Fri Feb 7 00:46:36 PST 2014


On Friday, 7 February 2014 at 08:24:39 UTC, Walter Bright wrote:
> https://github.com/D-Programming-Language/phobos/pull/1911
>
> This adds a package std.buffer, and the first entry in that 
> package, std.buffer.scopebuffer.

About to go to bed so just a couple of quick thoughts.

Why not just stick the stack array in ScopeBuffer itself (the
size could be a template parameter)? Escaping a ScopeBuffer is
rarely safe when it takes an external static array but if it
packed its own static array you could safely return it safely.

Also, if it did embed the static array in the ScopeBuffer I
wonder if it could just use the pointer as the buffer if the
length is less than size_t (short string optimization).

(Just thinking aloud, I wonder if std.allocators could be used to
implement this more generically (hypothetically: alias
ScopeBuffer =
CustomAllocOutputRange!(StaticWithMallocFallbackAllocator!10)))

It's a welcome addition and will go a long way toward cutting
down GC allocations once Phobos is output-range-ified. This 
technique is probably the first thing I'd reach for when choosing 
an output range.


More information about the Digitalmars-d mailing list