On Saturday, 1 April 2017 at 17:15:54 UTC, Inquie wrote:
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)
Cannot be done reliably without proper data-flow analysis.