]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: reduce list usage when not needed
authorCarsey, Jaben </o=Intel/ou=Americas01/cn=Workers/cn=Carsey, Jaben>
Tue, 10 Apr 2018 23:17:24 +0000 (07:17 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Tue, 17 Apr 2018 12:48:53 +0000 (20:48 +0800)
remove not needed lists.  some were just counted and others
should be sets.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/Python/AutoGen/GenC.py

index 58da9e6b1784a9573997d5814bc715ec768632d7..c11bbc5716f927e9ee22926a4953099fffe494da 100644 (file)
@@ -813,7 +813,7 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
     # AutoGen for each PCD listed in a [PcdEx] section of a Module/Lib INF file.\r
     # Auto generate a macro for each TokenName that takes a Guid pointer as a parameter.  \r
     # Use the Guid pointer to see if it matches any of the token space GUIDs.\r
-    TokenCNameList = []\r
+    TokenCNameList = set()\r
     for TokenCName in ExTokenCNameList:\r
         if TokenCName in TokenCNameList:\r
             continue\r
@@ -836,9 +836,9 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
                                     % (Pcd.TokenSpaceGuidCName, Pcd.TokenSpaceGuidCName, RealTokenCName))\r
                 if Index == Count:\r
                     AutoGenH.Append('0 \\\n  )\n')\r
-                TokenCNameList.append(TokenCName)\r
+                TokenCNameList.add(TokenCName)\r
     \r
-    TokenCNameList = []\r
+    TokenCNameList = set()\r
     for TokenCName in ExTokenCNameList:\r
         if TokenCName in TokenCNameList:\r
             continue\r
@@ -868,7 +868,7 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH):
                     #  COMPAREGUID() will only be used if the Guid passed in is local to the module.\r
                     AutoGenH.Append('#define _PCD_TOKEN_EX_%s(GuidPtr)   __PCD_%s_ADDR_CMP(GuidPtr) ? __PCD_%s_ADDR_CMP(GuidPtr) : __PCD_%s_VAL_CMP(GuidPtr)  \n'\r
                                     % (RealTokenCName, RealTokenCName, RealTokenCName, RealTokenCName))\r
-                TokenCNameList.append(TokenCName)\r
+                TokenCNameList.add(TokenCName)\r
 \r
 def GetPcdSize(Pcd):\r
     if Pcd.DatumType not in _NumericDataTypesList:\r
@@ -962,19 +962,22 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
     SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH[Pcd.DatumType] + '_S_' + TokenCName if Pcd.DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH['VOID*'] + '_S_' + TokenCName\r
     GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName\r
     \r
-    PcdExCNameList  = []\r
     if Pcd.Type in gDynamicExPcd:\r
         if Info.IsLibrary:\r
             PcdList = Info.LibraryPcdList\r
         else:\r
             PcdList = Info.ModulePcdList\r
+        PcdExCNameTest = 0\r
         for PcdModule in PcdList:\r
-            if PcdModule.Type in gDynamicExPcd:\r
-                PcdExCNameList.append(PcdModule.TokenCName)\r
+            if PcdModule.Type in gDynamicExPcd and Pcd.TokenCName == PcdModule.TokenCName:\r
+                PcdExCNameTest += 1\r
+            # get out early once we found > 1...\r
+            if PcdExCNameTest > 1:\r
+                break\r
         # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.\r
         # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.\r
         # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.\r
-        if PcdExCNameList.count(Pcd.TokenCName) > 1:\r
+        if PcdExCNameTest > 1:\r
             AutoGenH.Append('// Disabled the macros, as PcdToken and PcdGet/Set are not allowed in the case that more than one DynamicEx Pcds are different Guids but same CName.\n')\r
             AutoGenH.Append('// #define %s  %s\n' % (PcdTokenName, PcdExTokenName))\r
             AutoGenH.Append('// #define %s  LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
@@ -996,14 +999,14 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                 AutoGenH.Append('#define %s(Value)  LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
                 AutoGenH.Append('#define %s(Value)  LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
     elif Pcd.Type in gDynamicPcd:\r
-        PcdList = []\r
-        PcdCNameList = []\r
-        PcdList.extend(Info.LibraryPcdList)\r
-        PcdList.extend(Info.ModulePcdList)\r
-        for PcdModule in PcdList:\r
-            if PcdModule.Type in gDynamicPcd:\r
-                PcdCNameList.append(PcdModule.TokenCName)\r
-        if PcdCNameList.count(Pcd.TokenCName) > 1:\r
+        PcdCNameTest = 0\r
+        for PcdModule in Info.LibraryPcdList + Info.ModulePcdList:\r
+            if PcdModule.Type in gDynamicPcd and Pcd.TokenCName == PcdModule.TokenCName:\r
+                PcdCNameTest += 1\r
+            # get out early once we found > 1...\r
+            if PcdCNameTest > 1:\r
+                break\r
+        if PcdCNameTest > 1:\r
             EdkLogger.error("build", AUTOGEN_ERROR, "More than one Dynamic Pcds [%s] are different Guids but same CName. They need to be changed to DynamicEx type to avoid the confliction.\n" % (TokenCName), ExtraData="[%s]" % str(Info.MetaFile.Path))\r
         else:\r
             AutoGenH.Append('#define %s  LibPcdGet%s(%s)\n' % (GetModeName, DatumSizeLib, PcdTokenName))\r
@@ -1265,7 +1268,6 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
             Type = '(VOID *)'\r
         Array = '[]'\r
     PcdItemType = Pcd.Type\r
-    PcdExCNameList  = []\r
     if PcdItemType in gDynamicExPcd:\r
         PcdExTokenName = '_PCD_TOKEN_' + TokenSpaceGuidCName + '_' + TokenCName\r
         AutoGenH.Append('\n#define %s  %dU\n' % (PcdExTokenName, TokenNumber))\r
@@ -1274,13 +1276,17 @@ def CreateLibraryPcdCode(Info, AutoGenC, AutoGenH, Pcd):
             PcdList = Info.LibraryPcdList\r
         else:\r
             PcdList = Info.ModulePcdList\r
+        PcdExCNameTest = 0\r
         for PcdModule in PcdList:\r
-            if PcdModule.Type in gDynamicExPcd:\r
-                PcdExCNameList.append(PcdModule.TokenCName)\r
+            if PcdModule.Type in gDynamicExPcd and Pcd.TokenCName == PcdModule.TokenCName:\r
+                PcdExCNameTest += 1\r
+            # get out early once we found > 1...\r
+            if PcdExCNameTest > 1:\r
+                break\r
         # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.\r
         # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.\r
         # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.\r
-        if PcdExCNameList.count(Pcd.TokenCName) > 1:\r
+        if PcdExCNameTest > 1:\r
             AutoGenH.Append('// Disabled the macros, as PcdToken and PcdGet/Set are not allowed in the case that more than one DynamicEx Pcds are different Guids but same CName.\n')\r
             AutoGenH.Append('// #define %s  %s\n' % (PcdTokenName, PcdExTokenName))\r
             AutoGenH.Append('// #define %s  LibPcdGetEx%s(&%s, %s)\n' % (GetModeName, DatumSizeLib, Pcd.TokenSpaceGuidCName, PcdTokenName))\r
@@ -1696,7 +1702,7 @@ def CreatePcdCode(Info, AutoGenC, AutoGenH):
     AutoGenH.Append("\n// Definition of SkuId Array\n")\r
     AutoGenH.Append("extern UINT64 _gPcd_SkuId_Array[];\n")\r
     # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found\r
-    if TokenSpaceList <> []:            \r
+    if TokenSpaceList:\r
         AutoGenH.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")\r
         if Info.ModuleType in ["USER_DEFINED", "BASE"]:\r
             GuidType = "GUID"\r