Browse Source

* streamline retrieval of attributes (both in TypInfo and RTTI units)

git-svn-id: trunk@42373 -
svenbarth 6 years ago
parent
commit
de15025a47
2 changed files with 10 additions and 18 deletions
  1. 3 3
      packages/rtl-objpas/src/inc/rtti.pp
  2. 7 15
      rtl/objpas/typinfo.pp

+ 3 - 3
packages/rtl-objpas/src/inc/rtti.pp

@@ -3397,7 +3397,7 @@ end;
 
 function TRttiProperty.GetAttributes: specialize TArray<TCustomAttribute>;
 var
-  i: Integer;
+  i: SizeInt;
   at: PAttributeTable;
 begin
   if not FAttributesResolved then
@@ -3405,9 +3405,9 @@ begin
       at := FPropInfo^.AttributeTable;
       if Assigned(at) then
         begin
-          SetLength(FAttributes, FPropInfo^.AttributeTable^.AttributeCount);
+          SetLength(FAttributes, at^.AttributeCount);
           for i := 0 to High(FAttributes) do
-            FAttributes[i] := TCustomAttribute(GetPropAttribute(FPropInfo, i));
+            FAttributes[i] := TCustomAttribute(GetAttribute(at, i));
         end;
       FAttributesResolved:=true;
     end;

+ 7 - 15
rtl/objpas/typinfo.pp

@@ -895,7 +895,7 @@ procedure SetDynArrayProp(Instance: TObject; PropInfo: PPropInfo; const Value: P
 // Extended RTTI
 function GetAttributeTable(TypeInfo: PTypeInfo): PAttributeTable;
 
-function GetPropAttribute(PropInfo: PPropInfo; AttributeNr: Word): TCustomAttribute;
+function GetPropAttribute(PropInfo: PPropInfo; AttributeNr: Word): TCustomAttribute; inline;
 
 function GetAttribute(AttributeTable: PAttributeTable; AttributeNr: Word): TCustomAttribute;
 
@@ -989,7 +989,7 @@ begin
     end;
 end;
 
-function GetPropData(TypeInfo : PTypeInfo; TypeData: PTypeData) : PPropData;
+function GetPropData(TypeInfo : PTypeInfo; TypeData: PTypeData) : PPropData; inline;
 var
   p: PtrUInt;
 begin
@@ -997,19 +997,6 @@ begin
   Result := PPropData(aligntoptr(Pointer(p)));
 end;
 
-function GetPropAttribute(PropInfo: PPropInfo; AttributeNr: Word): TCustomAttribute;
-var
-  attrtable: PAttributeTable;
-begin
-  attrtable := PropInfo^.AttributeTable;
-  if not Assigned(attrtable) or (AttributeNr >= attrtable^.AttributeCount) then
-    result := Nil
-  else
-    begin
-      result := attrtable^.AttributesList[AttributeNr]();
-    end;
-end;
-
 function GetAttribute(AttributeTable: PAttributeTable; AttributeNr: Word): TCustomAttribute;
 var
   AttributeProcList: TAttributeProcList;
@@ -1022,6 +1009,11 @@ begin
     end;
 end;
 
+function GetPropAttribute(PropInfo: PPropInfo; AttributeNr: Word): TCustomAttribute;
+begin
+  Result := GetAttribute(PropInfo^.AttributeTable, AttributeNr);
+end;
+
 Function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string;
 
   Var PS : PShortString;