On Sunday, 7 October 2012 at 07:36:08 UTC, Philippe Sigaud wrote:
On Sat, Oct 6, 2012 at 8:32 PM, Dmitry Olshansky <[email protected]> wrote:

Your current code may have some bad impact on performance:
return "(" ~ to!string(res.numerator) ~ "/" ~ to!string(res.denominator) ~
")";

Allocates 4 times. ~ operator is convenient shortcut to get job done but
it's unsuitable for building strings and formatted output.

And the solution is?

Appender and formattedWrite can do this with a minimal amount of memory allocations.

The best solution is of course the writeTo function from DIP9 [1], which hasn't been accepted yet for some reason.

[1] http://www.prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP9

Reply via email to