THRIFT-4318 Delphi performance improvements
Client: Delphi
Patch: Jens Geyer
This closes #1348
diff --git a/lib/delphi/src/Thrift.Protocol.JSON.pas b/lib/delphi/src/Thrift.Protocol.JSON.pas
index 71ee7ae..30600aa 100644
--- a/lib/delphi/src/Thrift.Protocol.JSON.pas
+++ b/lib/delphi/src/Thrift.Protocol.JSON.pas
@@ -103,7 +103,7 @@
private
FHasData : Boolean;
- FData : TBytes;
+ FData : Byte;
public
// Return and consume the next byte to be Read, either taking it from the
@@ -169,18 +169,18 @@
public
// IProtocol
- procedure WriteMessageBegin( const aMsg : IMessage); override;
+ procedure WriteMessageBegin( const aMsg : TThriftMessage); override;
procedure WriteMessageEnd; override;
- procedure WriteStructBegin( const struc: IStruct); override;
+ procedure WriteStructBegin( const struc: TThriftStruct); override;
procedure WriteStructEnd; override;
- procedure WriteFieldBegin( const field: IField); override;
+ procedure WriteFieldBegin( const field: TThriftField); override;
procedure WriteFieldEnd; override;
procedure WriteFieldStop; override;
- procedure WriteMapBegin( const map: IMap); override;
+ procedure WriteMapBegin( const map: TThriftMap); override;
procedure WriteMapEnd; override;
- procedure WriteListBegin( const list: IList); override;
+ procedure WriteListBegin( const list: TThriftList); override;
procedure WriteListEnd(); override;
- procedure WriteSetBegin( const set_: ISet ); override;
+ procedure WriteSetBegin( const set_: TThriftSet ); override;
procedure WriteSetEnd(); override;
procedure WriteBool( b: Boolean); override;
procedure WriteByte( b: ShortInt); override;
@@ -191,17 +191,17 @@
procedure WriteString( const s: string ); override;
procedure WriteBinary( const b: TBytes); override;
//
- function ReadMessageBegin: IMessage; override;
+ function ReadMessageBegin: TThriftMessage; override;
procedure ReadMessageEnd(); override;
- function ReadStructBegin: IStruct; override;
+ function ReadStructBegin: TThriftStruct; override;
procedure ReadStructEnd; override;
- function ReadFieldBegin: IField; override;
+ function ReadFieldBegin: TThriftField; override;
procedure ReadFieldEnd(); override;
- function ReadMapBegin: IMap; override;
+ function ReadMapBegin: TThriftMap; override;
procedure ReadMapEnd(); override;
- function ReadListBegin: IList; override;
+ function ReadListBegin: TThriftList; override;
procedure ReadListEnd(); override;
- function ReadSetBegin: ISet; override;
+ function ReadSetBegin: TThriftSet; override;
procedure ReadSetEnd(); override;
function ReadBool: Boolean; override;
function ReadByte: ShortInt; override;
@@ -437,21 +437,19 @@
if FHasData
then FHasData := FALSE
else begin
- SetLength( FData, 1);
- IJSONProtocol(FProto).Transport.ReadAll( FData, 0, 1);
+ IJSONProtocol(FProto).Transport.ReadAll( @FData, SizeOf(FData), 0, 1);
end;
- result := FData[0];
+ result := FData;
end;
function TJSONProtocolImpl.TLookaheadReader.Peek : Byte;
begin
if not FHasData then begin
- SetLength( FData, 1);
- IJSONProtocol(FProto).Transport.ReadAll( FData, 0, 1);
+ IJSONProtocol(FProto).Transport.ReadAll( @FData, SizeOf(FData), 0, 1);
FHasData := TRUE;
end;
- result := FData[0];
+ result := FData;
end;
@@ -681,7 +679,7 @@
end;
-procedure TJSONProtocolImpl.WriteMessageBegin( const aMsg : IMessage);
+procedure TJSONProtocolImpl.WriteMessageBegin( const aMsg : TThriftMessage);
begin
ResetContextStack; // THRIFT-1473
@@ -700,7 +698,7 @@
end;
-procedure TJSONProtocolImpl.WriteStructBegin( const struc: IStruct);
+procedure TJSONProtocolImpl.WriteStructBegin( const struc: TThriftStruct);
begin
WriteJSONObjectStart;
end;
@@ -712,7 +710,7 @@
end;
-procedure TJSONProtocolImpl.WriteFieldBegin( const field : IField);
+procedure TJSONProtocolImpl.WriteFieldBegin( const field : TThriftField);
begin
WriteJSONInteger(field.ID);
WriteJSONObjectStart;
@@ -731,7 +729,7 @@
// nothing to do
end;
-procedure TJSONProtocolImpl.WriteMapBegin( const map: IMap);
+procedure TJSONProtocolImpl.WriteMapBegin( const map: TThriftMap);
begin
WriteJSONArrayStart;
WriteJSONString( GetTypeNameForTypeID( map.KeyType));
@@ -748,7 +746,7 @@
end;
-procedure TJSONProtocolImpl.WriteListBegin( const list: IList);
+procedure TJSONProtocolImpl.WriteListBegin( const list: TThriftList);
begin
WriteJSONArrayStart;
WriteJSONString( GetTypeNameForTypeID( list.ElementType));
@@ -762,7 +760,7 @@
end;
-procedure TJSONProtocolImpl.WriteSetBegin( const set_: ISet);
+procedure TJSONProtocolImpl.WriteSetBegin( const set_: TThriftSet);
begin
WriteJSONArrayStart;
WriteJSONString( GetTypeNameForTypeID( set_.ElementType));
@@ -1051,11 +1049,11 @@
end;
-function TJSONProtocolImpl.ReadMessageBegin: IMessage;
+function TJSONProtocolImpl.ReadMessageBegin: TThriftMessage;
begin
ResetContextStack; // THRIFT-1473
- result := TMessageImpl.Create;
+ Init( result);
ReadJSONArrayStart;
if ReadJSONInteger <> VERSION
@@ -1073,10 +1071,10 @@
end;
-function TJSONProtocolImpl.ReadStructBegin : IStruct ;
+function TJSONProtocolImpl.ReadStructBegin : TThriftStruct ;
begin
ReadJSONObjectStart;
- result := TStructImpl.Create('');
+ Init( result);
end;
@@ -1086,11 +1084,11 @@
end;
-function TJSONProtocolImpl.ReadFieldBegin : IField;
+function TJSONProtocolImpl.ReadFieldBegin : TThriftField;
var ch : Byte;
str : string;
begin
- result := TFieldImpl.Create;
+ Init( result);
ch := FReader.Peek;
if ch = RBRACE[0]
then result.Type_ := TType.Stop
@@ -1110,10 +1108,10 @@
end;
-function TJSONProtocolImpl.ReadMapBegin : IMap;
+function TJSONProtocolImpl.ReadMapBegin : TThriftMap;
var str : string;
begin
- result := TMapImpl.Create;
+ Init( result);
ReadJSONArrayStart;
str := SysUtils.TEncoding.UTF8.GetString( ReadJSONString(FALSE));
@@ -1134,10 +1132,10 @@
end;
-function TJSONProtocolImpl.ReadListBegin : IList;
+function TJSONProtocolImpl.ReadListBegin : TThriftList;
var str : string;
begin
- result := TListImpl.Create;
+ Init( result);
ReadJSONArrayStart;
str := SysUtils.TEncoding.UTF8.GetString( ReadJSONString(FALSE));
@@ -1152,10 +1150,10 @@
end;
-function TJSONProtocolImpl.ReadSetBegin : ISet;
+function TJSONProtocolImpl.ReadSetBegin : TThriftSet;
var str : string;
begin
- result := TSetImpl.Create;
+ Init( result);
ReadJSONArrayStart;
str := SysUtils.TEncoding.UTF8.GetString( ReadJSONString(FALSE));