Merged revision(s) 41393-41394 from trunk:

* ppudump: Use buffered write when outputting to json or xml. It improves the output speed a lot.
........
* ppudump: Fixed warnings with -O3.
........

git-svn-id: branches/fixes_3_2@41615 -
This commit is contained in:
yury 2019-03-06 07:56:41 +00:00
parent cd3d2c2abc
commit 61568c5e3d
4 changed files with 55 additions and 20 deletions

View File

@ -593,9 +593,9 @@ var
s : string;
begin
s:='';
ntflags:=flags;
if flags<>0 then
begin
ntflags:=flags;
first:=true;
for i:=1to flagopts do
if (flags and flagopt[i].mask)<>0 then
@ -1030,6 +1030,9 @@ var
begin
with ppufile do
begin
fileindex:=0;
line:=0;
column:=0;
{
info byte layout in bits:
0-1 - amount of bytes for fileindex
@ -2385,9 +2388,9 @@ begin
write(', ');
write(managementoperatoropt[i].str);
end;
if not first then
writeln;
end;
if not first then
writeln;
end;
@ -4117,12 +4120,12 @@ begin
'J':
begin
nostdout:=True;
pout:=TPpuJsonOutput.Create(Output);
pout:=TPpuJsonOutput.Create(StdOutputHandle);
end;
'X':
begin
nostdout:=True;
pout:=TPpuXmlOutput.Create(Output);
pout:=TPpuXmlOutput.Create(StdOutputHandle);
end;
else
begin

View File

@ -47,7 +47,7 @@ type
procedure WriteBool(const AName: string; AValue: boolean); override;
procedure WriteNull(const AName: string); override;
public
constructor Create(var OutFile: Text); override;
constructor Create(OutFileHandle: THandle); override;
procedure IncI; override;
procedure DecI; override;
end;
@ -214,9 +214,9 @@ begin
Write('}');
end;
constructor TPpuJsonOutput.Create(var OutFile: Text);
constructor TPpuJsonOutput.Create(OutFileHandle: THandle);
begin
inherited Create(OutFile);
inherited Create(OutFileHandle);
SetLength(FNeedDelim, 10);
FNeedDelim[0]:=False;
end;

View File

@ -39,11 +39,14 @@ type
{ TPpuOutput }
TPpuOutput = class
private
FOutFile: ^Text;
FOutFileHandle: THandle;
FOutBuf: array[0..10000] of char;
FOutBufPos: integer;
FIndent: integer;
FIndentSize: integer;
FIndStr: string;
FNoIndent: boolean;
procedure Flush;
procedure SetIndent(AValue: integer);
procedure SetIndentSize(AValue: integer);
protected
@ -57,7 +60,7 @@ type
procedure WriteBool(const AName: string; AValue: boolean); virtual;
procedure WriteNull(const AName: string); virtual;
public
constructor Create(var OutFile: Text); virtual;
constructor Create(OutFileHandle: THandle); virtual;
destructor Destroy; override;
procedure Write(const s: string);
procedure WriteLn(const s: string = '');
@ -1187,22 +1190,56 @@ begin
DecI;
end;
constructor TPpuOutput.Create(var OutFile: Text);
constructor TPpuOutput.Create(OutFileHandle: THandle);
begin
FOutFile:=@OutFile;
FOutFileHandle:=OutFileHandle;
FIndentSize:=2;
end;
destructor TPpuOutput.Destroy;
begin
Flush;
inherited Destroy;
end;
procedure TPpuOutput.Flush;
var
i, len: integer;
begin
i:=0;
while FOutBufPos > 0 do begin
len:=FileWrite(FOutFileHandle, FOutBuf[i], FOutBufPos);
if len < 0 then
raise Exception.CreateFmt('Error writing to file: ', [SysErrorMessage(GetLastOSError)]);
Inc(i, len);
Dec(FOutBufPos, len);
end;
end;
procedure TPpuOutput.Write(const s: string);
var
ss: string;
i, len, len2: integer;
begin
if not FNoIndent then
System.Write(FOutFile^, FIndStr);
System.Write(FOutFile^, s);
ss:=FIndStr + s
else
ss:=s;
i:=1;
len:=Length(ss);
while len > 0 do begin
len2:=Length(FOutBuf) - FOutBufPos;
if len2 > 0 then begin
if len < len2 then
len2:=len;
Move(ss[i], FOutBuf[FOutBufPos], len2);
Inc(FOutBufPos, len2);
end;
if FOutBufPos = Length(FOutBuf) then
Flush;
Inc(i, len2);
Dec(len, len2);
end;
FNoIndent:=True;
end;
@ -1228,6 +1265,7 @@ end;
procedure TPpuOutput.Done;
begin
Flush;
end;
{ TPpuUnitDef }

View File

@ -41,7 +41,6 @@ type
procedure WriteArrayEnd(const AName: string); override;
procedure WriteStr(const AName, AValue: string); override;
public
constructor Create(var OutFile: Text); override;
procedure Init; override;
end;
@ -162,11 +161,6 @@ begin
WriteLn(Format('</%s>', [GetTagName(Def.DefTypeName, 'object')]));
end;
constructor TPpuXmlOutput.Create(var OutFile: Text);
begin
inherited Create(OutFile);
end;
procedure TPpuXmlOutput.Init;
begin
inherited Init;