Jelajahi Sumber

* prefer write({short,ansi,wide}string) over write(chararray) for
constant strings

git-svn-id: trunk@9279 -

Jonas Maebe 17 tahun lalu
induk
melakukan
9f04aad33e
1 mengubah file dengan 22 tambahan dan 1 penghapusan
  1. 22 1
      compiler/ninl.pas

+ 22 - 1
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;