mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-22 07:09:29 +02:00
+ optimize <string>+'' and ''+<string>
git-svn-id: trunk@3522 -
This commit is contained in:
parent
33baacbe04
commit
454fb81c5b
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -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
|
||||
|
@ -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
18
tests/test/taddstr1.pp
Normal 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.
|
Loading…
Reference in New Issue
Block a user