Am 27.10.2014 11:07, schrieb Daniel Murphy:
"Benjamin Thaut"  wrote in message news:m2kt16$2566$1...@digitalmars.com...
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?

How ugly is it going to be, since druntime can't use std.format?

They wouldn't get any uglier than they already are, because the current toString functions within druntime also can't use std.format.

An example would be to toString function of TypInfo_StaticArray:

override string toString() const
{
        SizeStringBuff tmpBuff = void;
return value.toString() ~ "[" ~ cast(string)len.sizeToTempString(tmpBuff) ~ "]";
}

Would be replaced by:

override void toString(void delegate(const(char)[]) sink) const
{
        SizeStringBuff tmpBuff = void;
        value.toString(sink);
        sink("[");
        sink(cast(string)len.sizeToTempString(tmpBuff));
        sink("]");
}

The advantage would be that the new version now ideally never allocates. While the old version allocated 3 times of which 2 allocations end up beeing garbage right away.

Also I rember reading that the long term goal is to convert all toString functions to the sink version.

Kind Regards
Benjamin Thaut

Reply via email to