Preliminary submission - std.rational and std.typelist

Jakob Ovrum jakobovrum at gmail.com
Sun Oct 7 01:10:51 PDT 2012


On Sunday, 7 October 2012 at 07:36:08 UTC, Philippe Sigaud wrote:
> On Sat, Oct 6, 2012 at 8:32 PM, Dmitry Olshansky 
> <dmitry.olsh at gmail.com> 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



More information about the Digitalmars-d mailing list