From 9f04aad33ee2e65bfc9e82d5a04e702e24afa924 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sun, 18 Nov 2007 09:56:25 +0000 Subject: [PATCH] * prefer write({short,ansi,wide}string) over write(chararray) for constant strings git-svn-id: trunk@9279 - --- compiler/ninl.pas | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/compiler/ninl.pas b/compiler/ninl.pas index 0d96a23e47..0a173901bb 100644 --- a/compiler/ninl.pas +++ b/compiler/ninl.pas @@ -132,7 +132,7 @@ implementation end; - function tinlinenode.handle_str : tnode; + function tinlinenode.handle_str : tnode; var lenpara, fracpara, @@ -344,6 +344,23 @@ implementation end; + procedure maybe_convert_to_string(var n: tnode); + begin + { stringconstnodes are arrays of char. It's much more } + { efficient to write a constant string, so convert } + { either to shortstring or ansistring depending on } + { length } + if (n.nodetype=stringconstn) then + if is_chararray(n.resultdef) then + if (tstringconstnode(n).len<=255) then + inserttypeconv(n,cshortstringtype) + else + inserttypeconv(n,cansistringtype) + else if is_widechararray(n.resultdef) then + inserttypeconv(n,cwidestringtype); + end; + + function Tinlinenode.handle_text_read_write(filepara,params:Ttertiarynode;var newstatement:Tnode):boolean; {Read(ln)/write(ln) for text files.} @@ -390,6 +407,10 @@ implementation para.left:=p1; end; + if inlinenumber in [in_write_x,in_writeln_x] then + { prefer strings to chararrays } + maybe_convert_to_string(para.left); + case para.left.resultdef.typ of stringdef : name:=procprefixes[do_read]+tstringdef(para.left.resultdef).stringtypname;