View Issue Details

IDProjectCategoryView StatusLast Update
0037850pas2jsrtlpublic2020-10-06 13:35
Reporterhenrique Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformPas2JsOSWindows 
Fixed in Versiontrunk 
Summary0037850: Adjusted statement from RTTI
DescriptionI adjusted the declaration of the GetProperties function and getmethods. Now I store the values in an array, so as not to be creating every time.
TagsNo tags attached.
Fixed in Revision891
Attached Files

Activities

henrique

2020-10-01 16:25

reporter  

Rtti.patch (4,807 bytes)   
diff -r packages/rtl/rtti.pas (f38ae047) packages/rtl/rtti.pas (Working Tree)
28d27
< 
167c166,167
<   TRttiMethodArray = array of TRttiMethod;
---
> 
>   TRttiMethodArray = specialize TArray<TRttiMethod>;
193c193,194
<   TRttiPropertyArray = array of TRttiProperty;
---
> 
>   TRttiPropertyArray = specialize TArray<TRttiProperty>;
246a248,250
>   private
>     FMethods: TRttiMethodArray;
>     FProperties: TRttiPropertyArray;
248a253,259
>     function GetStructTypeInfo: TTypeInfoStruct;
>   public
>     constructor Create(ATypeInfo: PTypeInfo);
> 
>     destructor Destroy; override;
> 
>     function GetDeclaredMethods: TRttiMethodArray;
252a264
>     function GetProperties: TRttiPropertyArray;
254,256d265
<     function GetStructTypeInfo: TTypeInfoStruct;
<   public
<     constructor Create(ATypeInfo: PTypeInfo);
725c734
<   A, MethodCount: Integer;
---
>   A, Start: Integer;
728a738,739
>   Declared: TRttiMethodArray;
> 
731c742
<   MethodCount := 0;
---
>   Result := nil;
735,738c746,747
<     Inc(MethodCount, BaseClass.StructTypeInfo.MethodCount);
< 
<     BaseClass := BaseClass.GetAncestor;
<   end;
---
>     Declared := BaseClass.GetDeclaredMethods;
>     Start := Length(Result);
740c749
<   SetLength(Result, MethodCount);
---
>     SetLength(Result, Start + Length(Declared));
742,752c751,752
<   BaseClass := Self;
<   MethodCount := 0;
< 
<   while Assigned(BaseClass) do
<   begin
<     for A := 0 to Pred(BaseClass.StructTypeInfo.MethodCount) do
<     begin
<       Result[MethodCount] := TRttiMethod.Create(BaseClass, BaseClass.StructTypeInfo.GetMethod(A));
< 
<       Inc(MethodCount);
<     end;
---
>     for A := Low(Declared) to High(Declared) do
>       Result[Start + A] := Declared[A];
774c774,800
<     end;
---
>     end;
> end;
> 
> function TRttiStructuredType.GetProperties: TRttiPropertyArray;
> var
>   A, Start: Integer;
> 
>   BaseClass: TRttiStructuredType;
> 
>   Declared: TRttiPropertyArray;
> 
> begin
>   BaseClass := Self;
>   Result := nil;
> 
>   while Assigned(BaseClass) do
>   begin
>     Declared := BaseClass.GetDeclaredProperties;
>     Start := Length(Result);
> 
>     SetLength(Result, Start + Length(Declared));
> 
>     for A := Low(Declared) to High(Declared) do
>       Result[Start + A] := Declared[A];
> 
>     BaseClass := BaseClass.GetAncestor;
>   end;
789,790c815
<   A : Integer;
<   BaseClass : TRttiStructuredType;
---
>   Prop: TRttiProperty;
793,800c818,820
<   BaseClass := Self;
<   while Assigned(BaseClass) do
<      begin
<      for A := 0 to Pred(BaseClass.StructTypeInfo.PropCount) do
<        if StructTypeInfo.GetProp(A).Name = AName then
<          Exit(TRttiProperty.Create(BaseClass, BaseClass.StructTypeInfo.GetProp(A)));
<      BaseClass:=BaseClass.GetAncestor;
<      end;
---
>   for Prop in GetProperties do
>     if Prop.Name = AName then
>       Exit(Prop);
805c825
<   A, PropertyCount: Integer;
---
>   A: Integer;
807,808d826
<   BaseClass: TRttiStructuredType;
< 
810,813c828
<   BaseClass := Self;
<   PropertyCount := 0;
< 
<   while Assigned(BaseClass) do
---
>   if not Assigned(FProperties) then
815c830
<     Inc(PropertyCount, BaseClass.StructTypeInfo.PropCount);
---
>     SetLength(FProperties, StructTypeInfo.PropCount);
817,832c832,834
<     BaseClass := BaseClass.GetAncestor;
<   end;
< 
<   SetLength(Result, PropertyCount);
< 
<   BaseClass := Self;
<   PropertyCount := 0;
< 
<   while Assigned(BaseClass) do
<   begin
<     for A := 0 to Pred(BaseClass.StructTypeInfo.PropCount) do
<     begin
<       Result[PropertyCount] := TRttiProperty.Create(BaseClass, BaseClass.StructTypeInfo.GetProp(A));
< 
<       Inc(PropertyCount);
<     end;
---
>     for A := 0 to Pred(StructTypeInfo.PropCount) do
>       FProperties[A] := TRttiProperty.Create(Self, StructTypeInfo.GetProp(A));
>   end;
834,835c836
<     BaseClass := BaseClass.GetAncestor;
<   end;
---
>   Result := FProperties;
848a850,883
> end;
> 
> destructor TRttiStructuredType.Destroy;
> var
>   Method: TRttiMethod;
> 
>   Prop: TRttiProperty;
> 
> begin
>   for Method in FMethods do
>     Method.Free;
> 
>   for Prop in FProperties do
>     Prop.Free;
> 
>   inherited Destroy;
> end;
> 
> function TRttiStructuredType.GetDeclaredMethods: TRttiMethodArray;
> var
>   A, MethodCount: Integer;
> 
>   BaseClass: TRttiStructuredType;
> 
> begin
>   if not Assigned(FMethods) then
>   begin
>     SetLength(FMethods, StructTypeInfo.MethodCount);
> 
>     for A := 0 to Pred(StructTypeInfo.MethodCount) do
>       FMethods[MethodCount] := TRttiMethod.Create(Self, StructTypeInfo.GetMethod(A));
>   end;
> 
>   Result := FMethods;
Rtti.patch (4,807 bytes)   

Michael Van Canneyt

2020-10-06 10:27

administrator   ~0126108

Can you please provide a new patch against current trunk ?
It no longer applies cleanly, and it is too dangerous for me to try and apply it manually.

henrique

2020-10-06 13:16

reporter   ~0126111

There you go!
Rtti-2.patch (4,816 bytes)   
diff -r packages/rtl/rtti.pas (579f23ee) packages/rtl/rtti.pas (Working Tree)
28d27
< 
167c166,167
<   TRttiMethodArray = array of TRttiMethod;
---
> 
>   TRttiMethodArray = specialize TArray<TRttiMethod>;
193c193,194
<   TRttiPropertyArray = array of TRttiProperty;
---
> 
>   TRttiPropertyArray = specialize TArray<TRttiProperty>;
246a248,250
>   private
>     FMethods: TRttiMethodArray;
>     FProperties: TRttiPropertyArray;
248a253,259
>     function GetStructTypeInfo: TTypeInfoStruct;
>   public
>     constructor Create(ATypeInfo: PTypeInfo);
> 
>     destructor Destroy; override;
> 
>     function GetDeclaredMethods: TRttiMethodArray;
252a264
>     function GetProperties: TRttiPropertyArray;
254,256d265
<     function GetStructTypeInfo: TTypeInfoStruct;
<   public
<     constructor Create(ATypeInfo: PTypeInfo);
725c734,735
<   A, MethodCount: Integer;
---
>   A, Start: Integer;
> 
727a738,739
>   Declared: TRttiMethodArray;
> 
730c742
<   MethodCount := 0;
---
>   Result := nil;
733,745c745,749
<     Inc(MethodCount, BaseClass.StructTypeInfo.MethodCount);
<     BaseClass := BaseClass.GetAncestor;
<   end;
<   SetLength(Result, MethodCount);
<   BaseClass := Self;
<   MethodCount:=0;
<   while Assigned(BaseClass) do
<   begin
<     for A := 0 to Pred(BaseClass.StructTypeInfo.MethodCount) do
<     begin
<       Result[MethodCount] := TRttiMethod.Create(BaseClass, BaseClass.StructTypeInfo.GetMethod(A));
<       Inc(MethodCount);
<     end;
---
>     Declared := BaseClass.GetDeclaredMethods;
>     Start := Length(Result);
>     SetLength(Result, Start + Length(Declared));
>     for A := Low(Declared) to High(Declared) do
>       Result[Start + A] := Declared[A];
766c770,796
<     end;
---
>     end;
> end;
> 
> function TRttiStructuredType.GetProperties: TRttiPropertyArray;
> var
>   A, Start: Integer;
> 
>   BaseClass: TRttiStructuredType;
> 
>   Declared: TRttiPropertyArray;
> 
> begin
>   BaseClass := Self;
>   Result := nil;
> 
>   while Assigned(BaseClass) do
>   begin
>     Declared := BaseClass.GetDeclaredProperties;
>     Start := Length(Result);
> 
>     SetLength(Result, Start + Length(Declared));
> 
>     for A := Low(Declared) to High(Declared) do
>       Result[Start + A] := Declared[A];
> 
>     BaseClass := BaseClass.GetAncestor;
>   end;
781,782c811
<   A : Integer;
<   BaseClass : TRttiStructuredType;
---
>   Prop: TRttiProperty;
785,792c814,816
<   BaseClass := Self;
<   while Assigned(BaseClass) do
<      begin
<      for A := 0 to Pred(BaseClass.StructTypeInfo.PropCount) do
<        if StructTypeInfo.GetProp(A).Name = AName then
<          Exit(TRttiProperty.Create(BaseClass, BaseClass.StructTypeInfo.GetProp(A)));
<      BaseClass:=BaseClass.GetAncestor;
<      end;
---
>   for Prop in GetProperties do
>     if Prop.Name = AName then
>       Exit(Prop);
797c821
<   A, PropertyCount: Integer;
---
>   A, PropCount: Integer;
799,800d822
<   BaseClass: TRttiStructuredType;
< 
802,805c824
<   BaseClass := Self;
<   PropertyCount := 0;
< 
<   while Assigned(BaseClass) do
---
>   if not Assigned(FProperties) then
807c826
<     Inc(PropertyCount, BaseClass.StructTypeInfo.PropCount);
---
>     PropCount := StructTypeInfo.PropCount;
809,812c828
<     BaseClass := BaseClass.GetAncestor;
<   end;
< 
<   SetLength(Result, PropertyCount);
---
>     SetLength(FProperties, PropCount);
814,824c830,832
<   BaseClass := Self;
<   PropertyCount := 0;
< 
<   while Assigned(BaseClass) do
<   begin
<     for A := 0 to Pred(BaseClass.StructTypeInfo.PropCount) do
<     begin
<       Result[PropertyCount] := TRttiProperty.Create(BaseClass, BaseClass.StructTypeInfo.GetProp(A));
< 
<       Inc(PropertyCount);
<     end;
---
>     for A := 0 to Pred(PropCount) do
>       FProperties[A] := TRttiProperty.Create(Self, StructTypeInfo.GetProp(A));
>   end;
826,827c834
<     BaseClass := BaseClass.GetAncestor;
<   end;
---
>   Result := FProperties;
840a848,882
> end;
> 
> destructor TRttiStructuredType.Destroy;
> var
>   Method: TRttiMethod;
> 
>   Prop: TRttiProperty;
> 
> begin
>   for Method in FMethods do
>     Method.Free;
> 
>   for Prop in FProperties do
>     Prop.Free;
> 
>   inherited Destroy;
> end;
> 
> function TRttiStructuredType.GetDeclaredMethods: TRttiMethodArray;
> var
>   A, MethodCount: Integer;
> 
>   BaseClass: TRttiStructuredType;
> 
> begin
>   if not Assigned(FMethods) then
>   begin
>     MethodCount := StructTypeInfo.MethodCount;
>     SetLength(FMethods, MethodCount);
> 
>     for A := 0 to Pred(MethodCount) do
>       FMethods[A] := TRttiMethod.Create(Self, StructTypeInfo.GetMethod(A));
>   end;
> 
>   Result := FMethods;
Rtti-2.patch (4,816 bytes)   

Michael Van Canneyt

2020-10-06 13:25

administrator   ~0126113

Applied, thank you !

Issue History

Date Modified Username Field Change
2020-10-01 16:25 henrique New Issue
2020-10-01 16:25 henrique File Added: Rtti.patch
2020-10-06 10:27 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-10-06 10:27 Michael Van Canneyt Status new => feedback
2020-10-06 10:27 Michael Van Canneyt Note Added: 0126108
2020-10-06 13:01 henrique Status feedback => assigned
2020-10-06 13:16 henrique Note Added: 0126111
2020-10-06 13:16 henrique File Added: Rtti-2.patch
2020-10-06 13:25 Michael Van Canneyt Status assigned => resolved
2020-10-06 13:25 Michael Van Canneyt Resolution open => fixed
2020-10-06 13:25 Michael Van Canneyt Fixed in Version => trunk
2020-10-06 13:25 Michael Van Canneyt Fixed in Revision => 891
2020-10-06 13:25 Michael Van Canneyt Note Added: 0126113