Skip to content

Commit

Permalink
Optimization in TWTextFile.WriteLn
Browse files Browse the repository at this point in the history
In the way the method determines if the string can be saved as ANSI

Signed-off-by: Daniel Prado Velasco <dpradov@users.noreply.github.com>
  • Loading branch information
dpradov committed Apr 30, 2017
1 parent abb42d1 commit 9f28a03
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions support/gf_streams.pas
Expand Up @@ -78,7 +78,7 @@ TWTextFile = class


implementation
uses TntSystem, TntClasses;
uses TntSystem, TntClasses, gf_strings;


procedure SaveToFile(FN: WideString; Str: String);
Expand Down Expand Up @@ -414,14 +414,14 @@ function TWTextFile.Eof: boolean;
Result:= (posF = 0);
end;

{See: Variant Open Array Parameters}

procedure TWTextFile.WriteLn (const Args: array of const);
var
I: Integer;
line: string;
wline: WideString;
lastParamWide: boolean;
x: PShortString;
ws: wideString;
s: string;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9f28a03

Please sign in to comment.