浏览代码

fcl-passrc: do not allocate a temp list

(cherry picked from commit f50e6dfe8e1f84e98395f8de4683ad729b6895f2)
mattias 3 年之前
父节点
当前提交
b75ad2f4c9
共有 1 个文件被更改,包括 32 次插入41 次删除
  1. 32 41
      packages/fcl-passrc/src/pparser.pp

+ 32 - 41
packages/fcl-passrc/src/pparser.pp

@@ -7379,7 +7379,7 @@ begin
         for i:=OldCount to ARec.Members.Count-1 do
         for i:=OldCount to ARec.Members.Count-1 do
           begin
           begin
           CurEl:=TPasElement(ARec.Members[i]);
           CurEl:=TPasElement(ARec.Members[i]);
-          if CurEl.ClassType=TPasAttributes then continue;
+          if CurEl.ClassType<>TPasVariable then continue;
           if isClass then
           if isClass then
             With TPasVariable(CurEl) do
             With TPasVariable(CurEl) do
               VarModifiers:=VarModifiers + [vmClass];
               VarModifiers:=VarModifiers + [vmClass];
@@ -7457,14 +7457,11 @@ begin
         for i:=OldCount to ARec.Members.Count-1 do
         for i:=OldCount to ARec.Members.Count-1 do
           begin
           begin
           CurEl:=TPasElement(ARec.Members[i]);
           CurEl:=TPasElement(ARec.Members[i]);
-          if CurEl.ClassType=TPasAttributes then continue;
-          if CurEl.ClassType=TPasVariable then
-            begin
-            if isClass then
-              With TPasVariable(CurEl) do
-                VarModifiers:=VarModifiers + [vmClass];
-            Engine.FinishScope(stDeclaration,TPasVariable(CurEl));
-            end;
+          if CurEl.ClassType<>TPasVariable then continue;
+          if isClass then
+            With TPasVariable(CurEl) do
+              VarModifiers:=VarModifiers + [vmClass];
+          Engine.FinishScope(stDeclaration,TPasVariable(CurEl));
           end;
           end;
         end;
         end;
       tkSquaredBraceOpen:
       tkSquaredBraceOpen:
@@ -7610,43 +7607,37 @@ procedure TPasParser.ParseClassFields(AType: TPasClassType;
   const AVisibility: TPasMemberVisibility; IsClassField: Boolean);
   const AVisibility: TPasMemberVisibility; IsClassField: Boolean);
 
 
 Var
 Var
-  VarList: TFPList;
   Element: TPasElement;
   Element: TPasElement;
-  I : Integer;
+  I , OldCount: Integer;
   isStatic : Boolean;
   isStatic : Boolean;
   VarEl: TPasVariable;
   VarEl: TPasVariable;
+  Members: TFPList;
 
 
 begin
 begin
-  VarList := TFPList.Create;
-  try
-    ParseInlineVarDecl(AType, VarList, AVisibility, False);
-    if CurToken=tkSemicolon then
-      begin
-      NextToken;
-      isStatic:=CurTokenIsIdentifier('static');
-      if isStatic then
-        ExpectToken(tkSemicolon)
-      else
-        UngetToken;
-      end;
-    for i := 0 to VarList.Count - 1 do
-      begin
-      Element := TPasElement(VarList[i]);
-      Element.Visibility := AVisibility;
-      AType.Members.Add(Element);
-      if (Element is TPasVariable) then
-        begin
-        VarEl:=TPasVariable(Element);
-        if IsClassField then
-          Include(VarEl.VarModifiers,vmClass);
-        if isStatic then
-          Include(VarEl.VarModifiers,vmStatic);
-        Engine.FinishScope(stDeclaration,VarEl);
-        end;
-      end;
-  finally
-    VarList.Free;
-  end;
+  Members:=AType.Members;
+  OldCount:=Members.Count;
+  ParseInlineVarDecl(AType, Members, AVisibility, False);
+  if CurToken=tkSemicolon then
+    begin
+    NextToken;
+    isStatic:=CurTokenIsIdentifier('static');
+    if isStatic then
+      ExpectToken(tkSemicolon)
+    else
+      UngetToken;
+    end;
+  for i := OldCount to Members.Count - 1 do
+    begin
+    Element := TPasElement(Members[i]);
+    Element.Visibility := AVisibility;
+    if Element.ClassType<>TPasVariable then continue;
+    VarEl:=TPasVariable(Element);
+    if IsClassField then
+      Include(VarEl.VarModifiers,vmClass);
+    if isStatic then
+      Include(VarEl.VarModifiers,vmStatic);
+    Engine.FinishScope(stDeclaration,VarEl);
+    end;
 end;
 end;
 
 
 procedure TPasParser.ParseMembersLocalTypes(AType: TPasMembersType;
 procedure TPasParser.ParseMembersLocalTypes(AType: TPasMembersType;