Browse Source

* move initialization of TValue to a separate method to avoid duplicate implementations

Sven/Sarah Barth 3 years ago
parent
commit
f1059679a1
1 changed files with 13 additions and 12 deletions
  1. 13 12
      packages/rtl-objpas/src/inc/rtti.pp

+ 13 - 12
packages/rtl-objpas/src/inc/rtti.pp

@@ -110,6 +110,7 @@ type
     function GetTypeInfo: PTypeInfo; inline;
     function GetTypeKind: TTypeKind; inline;
     function GetIsEmpty: boolean; inline;
+    procedure Init; inline;
   public
     class function Empty: TValue; static;
     class procedure Make(ABuffer: pointer; ATypeInfo: PTypeInfo; out result: TValue); static;
@@ -1488,17 +1489,23 @@ end;
 
 { TValue }
 
-class function TValue.Empty: TValue;
+procedure TValue.Init;
 begin
-  result.FData.FTypeInfo := nil;
+  { resets the whole variant part; FValueData is already Nil }
 {$if SizeOf(TMethod) > SizeOf(QWord)}
-  Result.FData.FAsMethod.Code := Nil;
-  Result.FData.FAsMethod.Data := Nil;
+  FData.FAsMethod.Code := Nil;
+  FData.FAsMethod.Data := Nil;
 {$else}
-  Result.FData.FAsUInt64 := 0;
+  FData.FAsUInt64 := 0;
 {$endif}
 end;
 
+class function TValue.Empty: TValue;
+begin
+  Result.Init;
+  result.FData.FTypeInfo := nil;
+end;
+
 function TValue.GetTypeDataProp: PTypeData;
 begin
   result := GetTypeData(FData.FTypeInfo);
@@ -1605,14 +1612,8 @@ type
 var
   td: PTypeData;
 begin
+  result.Init;
   result.FData.FTypeInfo:=ATypeInfo;
-  { resets the whole variant part; FValueData is already Nil }
-{$if SizeOf(TMethod) > SizeOf(QWord)}
-  Result.FData.FAsMethod.Code := Nil;
-  Result.FData.FAsMethod.Data := Nil;
-{$else}
-  Result.FData.FAsUInt64 := 0;
-{$endif}
   if not Assigned(ATypeInfo) then
     Exit;
   { first handle those types that need a TValueData implementation }