toString refactor in druntime

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 31 12:07:25 PDT 2014


On Fri, Oct 31, 2014 at 12:04:24PM -0700, Walter Bright via Digitalmars-d wrote:
> On 10/27/2014 12:42 AM, Benjamin Thaut wrote:
> >I'm planning on doing a pull request for druntime which rewrites
> >every toString function within druntime to use the new sink
> >signature. That way druntime would cause a lot less allocations which
> >end up beeing garbage right away. Are there any objections against
> >doing so? Any reasons why such a pull request would not get accepted?
> 
> Why a sink version instead of an Output Range?

To allow toString to be a virtual function, perhaps?

Besides, the sink version basically allows encapsulation of an output
range -- instead of calling x.toString(outputRange) you just write:

	x.toString((const(char)[] data) { outputRange.put(data); });

Most of the time, you don't even need to bother with this, because given
an output range, formattedWrite("%s"...) will automatically figure out
which overload of toString to call and what arguments to pass to it.


T

-- 
The only difference between male factor and malefactor is just a little emptiness inside.


More information about the Digitalmars-d mailing list