Appending char[] to char[][] has unexpected results

Steven Schveighoffer schveiguy at yahoo.com
Wed May 1 22:43:13 PDT 2013


	On Wed, 01 May 2013 13:19:16 -0700, Peter Alexander  
<peter.alexander.au at gmail.com> wrote:


> The wchar and dchar versions don't reuse the buffer. Not sure why.  
> Here's the implementation, complete with relevant TODO

Wow, that is really awful.

Needs immediate improvement.  I would say the following code would be at  
least a bandaid-fix:

             ...
	    if(buf.length == buf.capacity) {
		buf.length = 0;
		buf.assumeSafeAppend();
             } else {
		buf.length = 0;
	    }
             foreach (wchar c; s)
             {
                 buf ~= c;
             }
             ...

Refactor as desired.

-Steve


More information about the Digitalmars-d mailing list