optimatization suggestion

Inquie via Digitalmars-d digitalmars-d at puremagic.com
Sat Apr 1 10:15:54 PDT 2017


I use a lot of code that has string appending and it seems like 
it could be optimized;

wchar[] x;

x ~= "This is one line";
x ~= "This is another line";

could become

x ~= "This is one lineThis is another line";

The rewrite rule is very simple:

if char type array is being appended to with literal string and 
next line also has appender with literal string, then combine in 
to one appender.

More complex cases could be handled such as

x ~= "This is one"~x~" line";
x ~= "This is another line";

which turns in to

x ~= "This is one"~x~" lineThis is another line";

Since these are done in ctfe, it may improve the speed 
significantly in some cases!? (usually the splitting up is for 
readability and to allow for easy modification)



More information about the Digitalmars-d mailing list