+ optimize <string>+'' and ''+<string>

git-svn-id: trunk@3522 -
This commit is contained in:
florian 2006-05-14 09:43:53 +00:00
parent 33baacbe04
commit 454fb81c5b
3 changed files with 33 additions and 0 deletions

1
.gitattributes vendored
View File

@ -5619,6 +5619,7 @@ tests/test/opt/treg2.pp svneol=native#text/plain
tests/test/opt/treg3.pp svneol=native#text/plain
tests/test/opt/treg4.pp svneol=native#text/plain
tests/test/tabstrcl.pp svneol=native#text/plain
tests/test/taddstr1.pp svneol=native#text/plain
tests/test/talign.pp svneol=native#text/plain
tests/test/talign1.pp svneol=native#text/plain
tests/test/talign2.pp svneol=native#text/plain

View File

@ -1561,6 +1561,20 @@ implementation
case nodetype of
addn:
begin
if (left.nodetype=stringconstn) and (tstringconstnode(left).len=0) then
begin
result:=right;
left:=nil;
right:=nil;
exit;
end;
if (right.nodetype=stringconstn) and (tstringconstnode(right).len=0) then
begin
result:=left;
left:=nil;
right:=nil;
exit;
end;
{ create the call to the concat routine both strings as arguments }
result := ccallnode.createintern('fpc_'+
tstringdef(resulttype.def).stringtypname+'_concat',

18
tests/test/taddstr1.pp Normal file
View File

@ -0,0 +1,18 @@
{ tests if '' is optimized properly in string concatenations }
var
s1 : string;
s2 : string;
begin
s1:='asdf';
if s1+''<>s1 then
halt(1);
s1:='asdf';
if ''+s1<>s1 then
halt(1);
if ''+s2+''+s1+''<>s2+s1 then
halt(1);
writeln('ok');
end.