Tips for fast string concatenation?
John Colvin
john.loughran.colvin at gmail.com
Fri Jun 21 05:52:19 PDT 2013
On Friday, 21 June 2013 at 11:33:29 UTC, monarch_dodra wrote:
> On Friday, 21 June 2013 at 10:09:10 UTC, Gary Willoughby wrote:
>> Have you any tips for using D when you need fast string
>> concatenation? I regularly use code like this:
>>
>> foreach (i, range)
>> {
>> foo ~= bar;
>> }
>>
>> or:
>>
>> foo = foo ~ bar ~ baz ~ qux;
>>
>> I've used std.string.format(...) in some instances which sped
>> things up which surprised me.
>>
>> Are there faster ways of appending strings?
>
> Regardless of whether you end up using lots of ~=, or Appender
> (possibly with formattedWrite), using reserve never hurts.
It's worth pointing out that Appender supports ~= so it's very
easy to swap it in, replacing builtin concatenation.
More information about the Digitalmars-d-learn
mailing list