On 31.08.19 14:07, cc wrote:
I'm guessing it's allocating a string first to write the contents of the array and then inserting that string into the buffer I supplied. Is there no way to have it skip this step and just write each element (plus the joining punctuation, etc) directly into the buffer?
`formatElement` does something like that. It writes the string into a temporary buffer while looking for invalid Unicode. When it finds some, the temporary is discarded and the whole string is formatted differently. When the string is a-ok, the data is copied over to the actual destination.
I'm not sure if that's the best approach, though. The temporary buffer and the string copy are costly.
There is also a closure being allocated for no reason in `sformat` itself. The compiler isn't smart enough to see that it's not really needed.
I've made a pull request to get rid of those allocations: https://github.com/dlang/phobos/pull/7163