From 9f28a03da58ae5e0d26cff87dee470c8f47e04d1 Mon Sep 17 00:00:00 2001 From: Daniel Prado Velasco Date: Sun, 30 Apr 2017 22:13:00 +0200 Subject: [PATCH] Optimization in TWTextFile.WriteLn In the way the method determines if the string can be saved as ANSI Signed-off-by: Daniel Prado Velasco --- support/gf_streams.pas | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/support/gf_streams.pas b/support/gf_streams.pas index 398cc20..ba15a1e 100644 --- a/support/gf_streams.pas +++ b/support/gf_streams.pas @@ -78,7 +78,7 @@ TWTextFile = class implementation -uses TntSystem, TntClasses; +uses TntSystem, TntClasses, gf_strings; procedure SaveToFile(FN: WideString; Str: String); @@ -414,6 +414,7 @@ function TWTextFile.Eof: boolean; Result:= (posF = 0); end; +{See: Variant Open Array Parameters} procedure TWTextFile.WriteLn (const Args: array of const); var @@ -421,7 +422,6 @@ procedure TWTextFile.WriteLn (const Args: array of const); line: string; wline: WideString; lastParamWide: boolean; - x: PShortString; ws: wideString; s: string; @@ -430,10 +430,7 @@ procedure TWTextFile.WriteLn (const Args: array of const); S: AnsiString; begin if (wline <> '') and (not lastParamWide or force) then begin - S:= string(wline); // To make it more compatible with older versions. Only use UTF8 if it's necessary - if wline <> WideString(S) then - S:= WideStringToUTF8(wline); - + S:= WideStringToUTF8(wline); F.WriteBuffer(PChar(S)^, length(S)); wline:= ''; end; @@ -463,16 +460,16 @@ procedure TWTextFile.WriteLn (const Args: array of const); lastParamWide:= true; end; vtPWideChar, - vtWideString: begin - ws:= WideString(Args [I].VPWideChar); - s:= string(ws); - if s = ws then - line := line + s - else begin - wline:= wline + ws; - lastParamWide:= true; - end; - end; + vtWideString: + begin + ws:= WideString(Args [I].VPWideChar); + if CanSaveAsANSI(ws) then + line:= line + string(ws) // To make it more compatible with older versions. Only use UTF8 if it's necessary + else begin + wline:= wline + ws; + lastParamWide:= true; + end; + end; vtCurrency: line := line + CurrToStr(Args [I].VCurrency^); end; // case checkToWrite;