From 454fb81c5b4981a668d897557c5c8030510620a2 Mon Sep 17 00:00:00 2001 From: florian Date: Sun, 14 May 2006 09:43:53 +0000 Subject: [PATCH] + optimize +'' and ''+ git-svn-id: trunk@3522 - --- .gitattributes | 1 + compiler/nadd.pas | 14 ++++++++++++++ tests/test/taddstr1.pp | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 tests/test/taddstr1.pp diff --git a/.gitattributes b/.gitattributes index 45cbf922da..760a5e2c38 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/compiler/nadd.pas b/compiler/nadd.pas index e7cd84770a..4f9f19ed8b 100644 --- a/compiler/nadd.pas +++ b/compiler/nadd.pas @@ -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', diff --git a/tests/test/taddstr1.pp b/tests/test/taddstr1.pp new file mode 100644 index 0000000000..bb47b67608 --- /dev/null +++ b/tests/test/taddstr1.pp @@ -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. \ No newline at end of file