optimatization suggestion
Stefan Koch via Digitalmars-d
digitalmars-d at puremagic.com
Sat Apr 1 15:41:35 PDT 2017
On Saturday, 1 April 2017 at 22:38:58 UTC, Stefan Koch wrote:
> 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.
Besides, it would generate almost the same code under the hood.
Unless we do something really clever, it's not going to safe much
time.
Significant improvements are not expected.
More information about the Digitalmars-d
mailing list