On Friday, June 21, 2013 12:09:09 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?
In general, ~= will be faster, beacause it won't create temporaries like concatenating a bunch of strings in a single expression would. However, if you want faster appending, generally the thing to use is std.array.Appender. And if you want to use format strings, it can be used with std.format.formattedWrite. - Jonathan M Davis