public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity
@ 2018-04-05 23:13 Jaben Carsey
  2018-04-05 23:13 ` [PATCH v1 01/14] BaseTools: remove unused file Jaben Carsey
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: Jaben Carsey @ 2018-04-05 23:13 UTC (permalink / raw)
  To: edk2-devel

group of changes to make code smaller and reduce overhead.

Jaben Carsey (14):
  BaseTools: remove unused file
  BaseTools: remove uncalled functions
  BaseTools: defaultdict(set) allows us to just add to the set
  BaseTools: sets are faster to check via "in" due to hashing
  BaseTools: replace a dict with a set
  BaseTools: remove unused variables
  BaseTools: change list to set
  BaseTools: simplify testing for existance and containing data
  BaseTools: optimize buildoptions loop
  BaseTools: change another list to set
  BaseTools: remove unneeded function call
  BaseTools: change more list to set
  BaseTools: GenC - move content from both parts of if/else
  BaseTools: refactor and remove out of date use of .keys()

 BaseTools/Scripts/SmiHandlerProfileSymbolGen.py           |   4 +-
 BaseTools/Source/Python/AutoGen/AutoGen.py                | 101 +++++++-------------
 BaseTools/Source/Python/AutoGen/BuildEngine.py            |  29 ++----
 BaseTools/Source/Python/AutoGen/GenC.py                   |   6 +-
 BaseTools/Source/Python/AutoGen/GenMake.py                |   2 +-
 BaseTools/Source/Python/Common/Dictionary.py              |  76 ---------------
 BaseTools/Source/Python/Common/TargetTxtClassObject.py    |  27 ------
 BaseTools/Source/Python/Common/ToolDefClassObject.py      |   7 +-
 BaseTools/Source/Python/GenFds/Fv.py                      |   2 +-
 BaseTools/Source/Python/GenFds/Section.py                 |   5 +-
 BaseTools/Source/Python/TargetTool/TargetTool.py          |   3 +-
 BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py |   5 +-
 BaseTools/Source/Python/build/build.py                    |   4 +-
 13 files changed, 59 insertions(+), 212 deletions(-)
 delete mode 100644 BaseTools/Source/Python/Common/Dictionary.py

-- 
2.16.2.windows.1



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v1 01/14] BaseTools: remove unused file
  2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
@ 2018-04-05 23:13 ` Jaben Carsey
  2018-04-05 23:13 ` [PATCH v1 02/14] BaseTools: remove uncalled functions Jaben Carsey
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jaben Carsey @ 2018-04-05 23:13 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

ToolsDefClassObject didnt need Dictionary, it needed an import from there.

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>
---
 BaseTools/Source/Python/Common/Dictionary.py         | 76 --------------------
 BaseTools/Source/Python/Common/ToolDefClassObject.py |  7 +-
 2 files changed, 5 insertions(+), 78 deletions(-)

diff --git a/BaseTools/Source/Python/Common/Dictionary.py b/BaseTools/Source/Python/Common/Dictionary.py
deleted file mode 100644
index f653275ff13f..000000000000
--- a/BaseTools/Source/Python/Common/Dictionary.py
+++ /dev/null
@@ -1,76 +0,0 @@
-## @file
-# Define a dictionary structure
-#
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
-# This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution.  The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-#
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-
-##
-# Import Modules
-#
-import EdkLogger
-from DataType import *
-from Common.LongFilePathSupport import OpenLongFilePath as open
-
-## Convert a text file to a dictionary
-#
-# Convert a text file to a dictionary of (name:value) pairs.
-#
-# @retval 0  Convert successful
-# @retval 1  Open file failed
-#
-def ConvertTextFileToDictionary(FileName, Dictionary, CommentCharacter, KeySplitCharacter, ValueSplitFlag, ValueSplitCharacter):
-    try:
-        F = open(FileName, 'r')
-        Keys = []
-        for Line in F:
-            if Line.startswith(CommentCharacter):
-                continue
-            LineList = Line.split(KeySplitCharacter, 1)
-            if len(LineList) >= 2:
-                Key = LineList[0].split()
-            if len(Key) == 1 and Key[0][0] != CommentCharacter and Key[0] not in Keys:
-                if ValueSplitFlag:
-                    Dictionary[Key[0]] = LineList[1].replace('\\', '/').split(ValueSplitCharacter)
-                else:
-                    Dictionary[Key[0]] = LineList[1].strip().replace('\\', '/')
-                Keys += [Key[0]]
-        F.close()
-        return 0
-    except:
-        EdkLogger.info('Open file failed')
-        return 1
-
-## Print the dictionary
-#
-# Print all items of dictionary one by one
-#
-# @param Dict:  The dictionary to be printed
-#
-def printDict(Dict):
-    if Dict is not None:
-        KeyList = Dict.keys()
-        for Key in KeyList:
-            if Dict[Key] != '':
-                print Key + ' = ' + str(Dict[Key])
-
-## Print the dictionary
-#
-# Print the items of dictionary which matched with input key
-#
-# @param list:  The dictionary to be printed
-# @param key:   The key of the item to be printed
-#
-def printList(Key, List):
-    if type(List) == type([]):
-        if len(List) > 0:
-            if Key.find(TAB_SPLIT) != -1:
-                print "\n" + Key
-                for Item in List:
-                    print Item
diff --git a/BaseTools/Source/Python/Common/ToolDefClassObject.py b/BaseTools/Source/Python/Common/ToolDefClassObject.py
index 1ab848f1ec68..73ebdaf6b179 100644
--- a/BaseTools/Source/Python/Common/ToolDefClassObject.py
+++ b/BaseTools/Source/Python/Common/ToolDefClassObject.py
@@ -1,7 +1,7 @@
 ## @file
 # This file is used to define each component of tools_def.txt file
 #
-# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
 # This program and the accompanying materials
 # are licensed and made available under the terms and conditions of the BSD License
 # which accompanies this distribution.  The full text of the license may be found at
@@ -18,7 +18,6 @@ import Common.LongFilePathOs as os
 import re
 import EdkLogger
 
-from Dictionary import *
 from BuildToolError import *
 from TargetTxtClassObject import *
 from Common.LongFilePathSupport import OpenLongFilePath as open
@@ -27,6 +26,10 @@ from Common.String import NormPath
 import Common.GlobalData as GlobalData
 from Common import GlobalData
 from Common.MultipleWorkspace import MultipleWorkspace as mws
+from DataType import TAB_TOD_DEFINES_TARGET,TAB_TOD_DEFINES_TOOL_CHAIN_TAG,\
+                     TAB_TOD_DEFINES_TARGET_ARCH,TAB_TOD_DEFINES_COMMAND_TYPE\
+                     ,TAB_TOD_DEFINES_FAMILY,TAB_TOD_DEFINES_BUILDRULEFAMILY
+
 
 ##
 # Static variables used for pattern
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 02/14] BaseTools: remove uncalled functions
  2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
  2018-04-05 23:13 ` [PATCH v1 01/14] BaseTools: remove unused file Jaben Carsey
@ 2018-04-05 23:13 ` Jaben Carsey
  2018-04-05 23:13 ` [PATCH v1 03/14] BaseTools: defaultdict(set) allows us to just add to the set Jaben Carsey
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jaben Carsey @ 2018-04-05 23:13 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

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>
---
 BaseTools/Source/Python/Common/TargetTxtClassObject.py | 27 --------------------
 1 file changed, 27 deletions(-)

diff --git a/BaseTools/Source/Python/Common/TargetTxtClassObject.py b/BaseTools/Source/Python/Common/TargetTxtClassObject.py
index 0ba7725dd5b5..f8459c892e36 100644
--- a/BaseTools/Source/Python/Common/TargetTxtClassObject.py
+++ b/BaseTools/Source/Python/Common/TargetTxtClassObject.py
@@ -137,33 +137,6 @@ class TargetTxtClassObject(object):
         F.close()
         return 0
 
-    ## Print the dictionary
-    #
-    # Print all items of dictionary one by one
-    #
-    # @param Dict:  The dictionary to be printed
-    #
-    def printDict(Dict):
-        if Dict is not None:
-            KeyList = Dict.keys()
-            for Key in KeyList:
-                if Dict[Key] != '':
-                    print Key + ' = ' + str(Dict[Key])
-
-    ## Print the dictionary
-    #
-    # Print the items of dictionary which matched with input key
-    #
-    # @param list:  The dictionary to be printed
-    # @param key:   The key of the item to be printed
-    #
-    def printList(Key, List):
-        if type(List) == type([]):
-            if len(List) > 0:
-                if Key.find(TAB_SPLIT) != -1:
-                    print "\n" + Key
-                    for Item in List:
-                        print Item
 ## TargetTxtDict
 #
 # Load target.txt in input Conf dir
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 03/14] BaseTools: defaultdict(set) allows us to just add to the set
  2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
  2018-04-05 23:13 ` [PATCH v1 01/14] BaseTools: remove unused file Jaben Carsey
  2018-04-05 23:13 ` [PATCH v1 02/14] BaseTools: remove uncalled functions Jaben Carsey
@ 2018-04-05 23:13 ` Jaben Carsey
  2018-04-05 23:13 ` [PATCH v1 04/14] BaseTools: sets are faster to check via "in" due to hashing Jaben Carsey
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jaben Carsey @ 2018-04-05 23:13 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

New sets will get created automatically when needed

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>
---
 BaseTools/Source/Python/AutoGen/AutoGen.py | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index 3384fdb70b7e..91a0742a33be 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -45,6 +45,7 @@ import InfSectionParser
 import datetime
 import hashlib
 from GenVar import VariableMgr,var_info
+from collections import defaultdict
 
 ## Regular expression for splitting Dependency Expression string into tokens
 gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")
@@ -3495,8 +3496,8 @@ class ModuleAutoGen(AutoGen):
         if self._BuildTargets is None:
             self._IntroBuildTargetList = set()
             self._FinalBuildTargetList = set()
-            self._BuildTargets = {}
-            self._FileTypes = {}
+            self._BuildTargets = defaultdict(set)
+            self._FileTypes = defaultdict(set)
 
         SubDirectory = os.path.join(self.OutputDir, File.SubDir)
         if not os.path.exists(SubDirectory):
@@ -3533,8 +3534,6 @@ class ModuleAutoGen(AutoGen):
                 break
 
             FileType = RuleObject.SourceFileType
-            if FileType not in self._FileTypes:
-                self._FileTypes[FileType] = set()
             self._FileTypes[FileType].add(Source)
 
             # stop at STATIC_LIBRARY for library
@@ -3552,8 +3551,6 @@ class ModuleAutoGen(AutoGen):
                 # Only do build for target with outputs
                 self._FinalBuildTargetList.add(Target)
 
-            if FileType not in self._BuildTargets:
-                self._BuildTargets[FileType] = set()
             self._BuildTargets[FileType].add(Target)
 
             if not Source.IsBinary and Source == File:
@@ -3572,8 +3569,8 @@ class ModuleAutoGen(AutoGen):
         if self._BuildTargets is None:
             self._IntroBuildTargetList = set()
             self._FinalBuildTargetList = set()
-            self._BuildTargets = {}
-            self._FileTypes = {}
+            self._BuildTargets = defaultdict(set)
+            self._FileTypes = defaultdict(set)
 
         #TRICK: call _GetSourceFileList to apply build rule for source files
         if self.SourceFileList:
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 04/14] BaseTools: sets are faster to check via "in" due to hashing
  2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
                   ` (2 preceding siblings ...)
  2018-04-05 23:13 ` [PATCH v1 03/14] BaseTools: defaultdict(set) allows us to just add to the set Jaben Carsey
@ 2018-04-05 23:13 ` Jaben Carsey
  2018-04-05 23:13 ` [PATCH v1 05/14] BaseTools: replace a dict with a set Jaben Carsey
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jaben Carsey @ 2018-04-05 23:13 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

switch list to set:
1)we dont care about order
2)we only check for membership.

then remove ".keys()" from dict looping:
allow generators opportunity to optimize

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>
---
 BaseTools/Source/Python/AutoGen/AutoGen.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index 91a0742a33be..bd720a4dd295 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -354,9 +354,9 @@ class WorkspaceAutoGen(AutoGen):
                     MetaFile_cache = {}
                     for Arch in self.ArchList:
                         Platform_cache[Arch] = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]
-                        MetaFile_cache[Arch] = []
-                        for Pkey in Platform_cache[Arch].Modules.keys():
-                            MetaFile_cache[Arch].append(Platform_cache[Arch].Modules[Pkey].MetaFile)
+                        MetaFile_cache[Arch] = set()
+                        for Pkey in Platform_cache[Arch].Modules:
+                            MetaFile_cache[Arch].add(Platform_cache[Arch].Modules[Pkey].MetaFile)
                     for Inf in self.FdfProfile.InfDict[key]:
                         ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)
                         for Arch in self.ArchList:
@@ -371,9 +371,9 @@ class WorkspaceAutoGen(AutoGen):
                     for Arch in self.ArchList:
                         if Arch == key:
                             Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]
-                            MetaFileList = []
-                            for Pkey in Platform.Modules.keys():
-                                MetaFileList.append(Platform.Modules[Pkey].MetaFile)
+                            MetaFileList = set()
+                            for Pkey in Platform.Modules:
+                                MetaFileList.add(Platform.Modules[Pkey].MetaFile)
                             for Inf in self.FdfProfile.InfDict[key]:
                                 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)
                                 if ModuleFile in MetaFileList:
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 05/14] BaseTools: replace a dict with a set
  2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
                   ` (3 preceding siblings ...)
  2018-04-05 23:13 ` [PATCH v1 04/14] BaseTools: sets are faster to check via "in" due to hashing Jaben Carsey
@ 2018-04-05 23:13 ` Jaben Carsey
  2018-04-05 23:13 ` [PATCH v1 06/14] BaseTools: remove unused variables Jaben Carsey
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jaben Carsey @ 2018-04-05 23:13 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

As we never use the values, just keep the keys in a set.

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>
---
 BaseTools/Source/Python/AutoGen/AutoGen.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index bd720a4dd295..cf76b8054467 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -554,11 +554,11 @@ class WorkspaceAutoGen(AutoGen):
                 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]
                 PkgSet.update(ModuleData.Packages)
             Pkgs = list(PkgSet) + list(PGen.PackageList)
-            DecPcds = {}
+            DecPcds = set()
             DecPcdsKey = set()
             for Pkg in Pkgs:
                 for Pcd in Pkg.Pcds:
-                    DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd]
+                    DecPcds.add((Pcd[0], Pcd[1]))
                     DecPcdsKey.add((Pcd[0], Pcd[1], Pcd[2]))
 
             Platform.SkuName = self.SkuId
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 06/14] BaseTools: remove unused variables
  2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
                   ` (4 preceding siblings ...)
  2018-04-05 23:13 ` [PATCH v1 05/14] BaseTools: replace a dict with a set Jaben Carsey
@ 2018-04-05 23:13 ` Jaben Carsey
  2018-04-05 23:13 ` [PATCH v1 07/14] BaseTools: change list to set Jaben Carsey
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jaben Carsey @ 2018-04-05 23:13 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

some were populated, but never used after.
some were never used.

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>
---
 BaseTools/Source/Python/AutoGen/AutoGen.py | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index cf76b8054467..d00cc6c6cd3b 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -1400,8 +1400,6 @@ class PlatformAutoGen(AutoGen):
 
         # for gathering error information
         NoDatumTypePcdList = set()
-        PcdNotInDb = []
-        self._GuidValue = {}
         FdfModuleList = []
         for InfName in self._AsBuildInfList:
             InfName = mws.join(self.WorkspaceDir, InfName)
@@ -1439,8 +1437,6 @@ class PlatformAutoGen(AutoGen):
                         if PcdFromModule.Type in GenC.gDynamicPcd and \
                             PcdFromModule.IsFromBinaryInf == False:
                             # Print warning message to let the developer make a determine.
-                            if PcdFromModule not in PcdNotInDb:
-                                PcdNotInDb.append(PcdFromModule)
                             continue
                         # If one of the Source built modules listed in the DSC is not listed in 
                         # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx 
@@ -1448,8 +1444,6 @@ class PlatformAutoGen(AutoGen):
                         # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the 
                         # PCD to the Platform's PCD Database.
                         if PcdFromModule.Type in GenC.gDynamicExPcd:
-                            if PcdFromModule not in PcdNotInDb:
-                                PcdNotInDb.append(PcdFromModule)
                             continue
                     #
                     # If a dynamic PCD used by a PEM module/PEI module & DXE module,
@@ -1930,7 +1924,6 @@ class PlatformAutoGen(AutoGen):
                 self._ToolDefinitions[Tool][Attr] = Value
 
             ToolsDef = ''
-            MakePath = ''
             if GlobalData.gOptions.SilentMode and "MAKE" in self._ToolDefinitions:
                 if "FLAGS" not in self._ToolDefinitions["MAKE"]:
                     self._ToolDefinitions["MAKE"]["FLAGS"] = ""
@@ -1951,9 +1944,7 @@ class PlatformAutoGen(AutoGen):
 
                     if Attr == "PATH":
                         # Don't put MAKE definition in the file
-                        if Tool == "MAKE":
-                            MakePath = Value
-                        else:
+                        if Tool != "MAKE":
                             ToolsDef += "%s = %s\n" % (Tool, Value)
                     elif Attr != "DLL":
                         # Don't put MAKE definition in the file
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 07/14] BaseTools: change list to set
  2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
                   ` (5 preceding siblings ...)
  2018-04-05 23:13 ` [PATCH v1 06/14] BaseTools: remove unused variables Jaben Carsey
@ 2018-04-05 23:13 ` Jaben Carsey
  2018-04-05 23:13 ` [PATCH v1 08/14] BaseTools: simplify testing for existance and containing data Jaben Carsey
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jaben Carsey @ 2018-04-05 23:13 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

Order is irelevant
duplication is auto-prevented

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>
---
 BaseTools/Source/Python/AutoGen/AutoGen.py | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index d00cc6c6cd3b..a8c49658bd21 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -3927,7 +3927,7 @@ class ModuleAutoGen(AutoGen):
     ## Create AsBuilt INF file the module
     #
     def CreateAsBuiltInf(self, IsOnlyCopy = False):
-        self.OutputFile = []
+        self.OutputFile = set()
         if IsOnlyCopy:
             if GlobalData.gBinCacheDest:
                 self.CopyModuleToCache()
@@ -4068,8 +4068,7 @@ class ModuleAutoGen(AutoGen):
         DebugDir = self.DebugDir.replace('\\', '/').strip('/')
         for Item in self.CodaTargetList:
             File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/')
-            if File not in self.OutputFile:
-                self.OutputFile.append(File)
+            self.OutputFile.add(File)
             if os.path.isabs(File):
                 File = File.replace('\\', '/').strip('/').replace(OutputDir, '').strip('/')
             if Item.Target.Ext.lower() == '.aml':
@@ -4081,8 +4080,7 @@ class ModuleAutoGen(AutoGen):
             else:
                 AsBuiltInfDict['binary_item'] += ['BIN|' + File]
         if self.DepexGenerated:
-            if self.Name + '.depex' not in self.OutputFile:
-                self.OutputFile.append(self.Name + '.depex')
+            self.OutputFile.add(self.Name + '.depex')
             if self.ModuleType in ['PEIM']:
                 AsBuiltInfDict['binary_item'] += ['PEI_DEPEX|' + self.Name + '.depex']
             if self.ModuleType in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:
@@ -4093,15 +4091,13 @@ class ModuleAutoGen(AutoGen):
         Bin = self._GenOffsetBin()
         if Bin:
             AsBuiltInfDict['binary_item'] += ['BIN|%s' % Bin]
-            if Bin not in self.OutputFile:
-                self.OutputFile.append(Bin)
+            self.OutputFile.add(Bin)
 
         for Root, Dirs, Files in os.walk(OutputDir):
             for File in Files:
                 if File.lower().endswith('.pdb'):
                     AsBuiltInfDict['binary_item'] += ['DISPOSABLE|' + File]
-                    if File not in self.OutputFile:
-                        self.OutputFile.append(File)
+                    self.OutputFile.add(File)
         HeaderComments = self.Module.HeaderComments
         StartPos = 0
         for Index in range(len(HeaderComments)):
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 08/14] BaseTools: simplify testing for existance and containing data
  2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
                   ` (6 preceding siblings ...)
  2018-04-05 23:13 ` [PATCH v1 07/14] BaseTools: change list to set Jaben Carsey
@ 2018-04-05 23:13 ` Jaben Carsey
  2018-04-05 23:13 ` [PATCH v1 09/14] BaseTools: optimize buildoptions loop Jaben Carsey
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jaben Carsey @ 2018-04-05 23:13 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

and remove a duplicate "if" block from 6 lines up.

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>
---
 BaseTools/Source/Python/AutoGen/AutoGen.py | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index a8c49658bd21..cc08baacfae5 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -2364,17 +2364,15 @@ class PlatformAutoGen(AutoGen):
                                              ToPcd.Type, Module, FromPcd.Type),
                                           File=self.MetaFile)
 
-            if FromPcd.MaxDatumSize not in [None, '']:
+            if FromPcd.MaxDatumSize:
                 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize
-            if FromPcd.DefaultValue not in [None, '']:
+            if FromPcd.DefaultValue:
                 ToPcd.DefaultValue = FromPcd.DefaultValue
-            if FromPcd.TokenValue not in [None, '']:
+            if FromPcd.TokenValue:
                 ToPcd.TokenValue = FromPcd.TokenValue
-            if FromPcd.MaxDatumSize not in [None, '']:
-                ToPcd.MaxDatumSize = FromPcd.MaxDatumSize
-            if FromPcd.DatumType not in [None, '']:
+            if FromPcd.DatumType:
                 ToPcd.DatumType = FromPcd.DatumType
-            if FromPcd.SkuInfoList not in [None, '', []]:
+            if FromPcd.SkuInfoList:
                 ToPcd.SkuInfoList = FromPcd.SkuInfoList
             # Add Flexible PCD format parse
             if ToPcd.DefaultValue:
@@ -3945,11 +3943,11 @@ class ModuleAutoGen(AutoGen):
             return
             
         # Skip the following code for modules with no source files
-        if self.SourceFileList is None or self.SourceFileList == []:
+        if not self.SourceFileList:
             return
 
         # Skip the following code for modules without any binary files
-        if self.BinaryFileList <> None and self.BinaryFileList <> []:
+        if not self.BinaryFileList:
             return
             
         ### TODO: How to handles mixed source and binary modules
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 09/14] BaseTools: optimize buildoptions loop
  2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
                   ` (7 preceding siblings ...)
  2018-04-05 23:13 ` [PATCH v1 08/14] BaseTools: simplify testing for existance and containing data Jaben Carsey
@ 2018-04-05 23:13 ` Jaben Carsey
  2018-04-05 23:13 ` [PATCH v1 10/14] BaseTools: change another list to set Jaben Carsey
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jaben Carsey @ 2018-04-05 23:13 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

change a dict to a double defaultdict to prevent needing to seed innter values.
move "Value" determination under a conditional continue statement

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>
---
 BaseTools/Source/Python/AutoGen/AutoGen.py | 21 ++++++--------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index cc08baacfae5..74828fdb62ef 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -2698,40 +2698,31 @@ class PlatformAutoGen(AutoGen):
         AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() +
                        PlatformModuleOptions.keys() + ModuleTypeOptions.keys() +
                        self.ToolDefinition.keys())
-        BuildOptions = {}
+        BuildOptions = defaultdict(lambda: defaultdict(str))
         for Tool in AllTools:
-            if Tool not in BuildOptions:
-                BuildOptions[Tool] = {}
-
             for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:
                 if Tool not in Options:
                     continue
                 for Attr in Options[Tool]:
-                    Value = Options[Tool][Attr]
                     #
                     # Do not generate it in Makefile
                     #
                     if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:
                         continue
-                    if Attr not in BuildOptions[Tool]:
-                        BuildOptions[Tool][Attr] = ""
+                    Value = Options[Tool][Attr]
                     # check if override is indicated
                     if Value.startswith('='):
-                        ToolPath = Value[1:]
-                        ToolPath = mws.handleWsMacro(ToolPath)
-                        BuildOptions[Tool][Attr] = ToolPath
+                        BuildOptions[Tool][Attr] = mws.handleWsMacro(Value[1:])
                     else:
-                        Value = mws.handleWsMacro(Value)
                         if Attr != 'PATH':
-                            BuildOptions[Tool][Attr] += " " + Value
+                            BuildOptions[Tool][Attr] += " " + mws.handleWsMacro(Value)
                         else:
-                            BuildOptions[Tool][Attr] = Value
+                            BuildOptions[Tool][Attr] = mws.handleWsMacro(Value)
+
         if Module.AutoGenVersion < 0x00010005 and self.Workspace.UniFlag is not None:
             #
             # Override UNI flag only for EDK module.
             #
-            if 'BUILD' not in BuildOptions:
-                BuildOptions['BUILD'] = {}
             BuildOptions['BUILD']['FLAGS'] = self.Workspace.UniFlag
         return BuildOptions, BuildRuleOrder
 
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 10/14] BaseTools: change another list to set
  2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
                   ` (8 preceding siblings ...)
  2018-04-05 23:13 ` [PATCH v1 09/14] BaseTools: optimize buildoptions loop Jaben Carsey
@ 2018-04-05 23:13 ` Jaben Carsey
  2018-04-05 23:13 ` [PATCH v1 11/14] BaseTools: remove unneeded function call Jaben Carsey
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jaben Carsey @ 2018-04-05 23:13 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

potentially accelerate "in" testing which is the use for this variable

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>
---
 BaseTools/Source/Python/AutoGen/AutoGen.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index 74828fdb62ef..c52386c8484a 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -3790,7 +3790,7 @@ class ModuleAutoGen(AutoGen):
         if not self.SourceFileList:
             return []
 
-        NameGuids = []
+        NameGuids = set()
         for SrcFile in self.SourceFileList:
             if SrcFile.Ext.lower() != '.vfr':
                 continue
@@ -3822,7 +3822,7 @@ class ModuleAutoGen(AutoGen):
                 if not Guid:
                     break
                 NameArray = ConvertStringToByteArray('L"' + Name.group(1) + '"')
-                NameGuids.append((NameArray, GuidStructureStringToGuidString(Guid.group(1))))
+                NameGuids.add((NameArray, GuidStructureStringToGuidString(Guid.group(1))))
                 Pos = Content.find('efivarstore', Name.end())
         if not NameGuids:
             return []
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 11/14] BaseTools: remove unneeded function call
  2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
                   ` (9 preceding siblings ...)
  2018-04-05 23:13 ` [PATCH v1 10/14] BaseTools: change another list to set Jaben Carsey
@ 2018-04-05 23:13 ` Jaben Carsey
  2018-04-05 23:14 ` [PATCH v1 12/14] BaseTools: change more list to set Jaben Carsey
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jaben Carsey @ 2018-04-05 23:13 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

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>
---
 BaseTools/Source/Python/AutoGen/AutoGen.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index c52386c8484a..42536a61535a 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -3897,7 +3897,6 @@ class ModuleAutoGen(AutoGen):
                 VfrGuid = [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
                 VfrGuid = [chr(ItemGuid) for ItemGuid in VfrGuid]
                 fStringIO.write(''.join(VfrGuid))                   
-                type (Item[1]) 
                 VfrValue = pack ('Q', int (Item[1], 16))
                 fStringIO.write (VfrValue)
         #
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 12/14] BaseTools: change more list to set
  2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
                   ` (10 preceding siblings ...)
  2018-04-05 23:13 ` [PATCH v1 11/14] BaseTools: remove unneeded function call Jaben Carsey
@ 2018-04-05 23:14 ` Jaben Carsey
  2018-04-05 23:14 ` [PATCH v1 13/14] BaseTools: GenC - move content from both parts of if/else Jaben Carsey
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Jaben Carsey @ 2018-04-05 23:14 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

potentially accelerate "in" testing
remove uncalled function

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>
---
 BaseTools/Source/Python/AutoGen/AutoGen.py     |  5 ++--
 BaseTools/Source/Python/AutoGen/BuildEngine.py | 29 ++++++--------------
 2 files changed, 10 insertions(+), 24 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index 42536a61535a..342cd618c605 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -4191,7 +4191,7 @@ class ModuleAutoGen(AutoGen):
                     PcdItem = PcdComments + '\n  ' + PcdItem
                 AsBuiltInfDict['patchablepcd_item'].append(PcdItem)
 
-        HiiPcds = []
+        HiiPcds = set()
         for Pcd in Pcds + VfrPcds:
             PcdComments = ''
             PcdCommentList = []
@@ -4214,8 +4214,7 @@ class ModuleAutoGen(AutoGen):
                 #
                 if (SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in HiiPcds:
                     continue
-                else:
-                    HiiPcds.append((SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
+                HiiPcds.add((SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
             if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:
                 PcdCommentList = self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName][:]
             if HiiInfo:
diff --git a/BaseTools/Source/Python/AutoGen/BuildEngine.py b/BaseTools/Source/Python/AutoGen/BuildEngine.py
index 0daed7da610d..1663ddd21bb0 100644
--- a/BaseTools/Source/Python/AutoGen/BuildEngine.py
+++ b/BaseTools/Source/Python/AutoGen/BuildEngine.py
@@ -161,7 +161,7 @@ class FileBuildRule:
 
         # Check input files
         self.IsMultipleInput = False
-        self.SourceFileExtList = []
+        self.SourceFileExtList = set()
         for File in Input:
             Base, Ext = os.path.splitext(File)
             if Base.find("*") >= 0:
@@ -172,8 +172,7 @@ class FileBuildRule:
                 # There's no "*" and "?" in file name
                 self.ExtraSourceFileList.append(File)
                 continue
-            if Ext not in self.SourceFileExtList:
-                self.SourceFileExtList.append(Ext)
+            self.SourceFileExtList.add(Ext)
 
         # Check output files
         self.DestFileList = []
@@ -194,16 +193,6 @@ class FileBuildRule:
         CommandString = "\n\t".join(self.CommandList)
         return "%s : %s\n\t%s" % (DestString, SourceString, CommandString)
 
-    ## Check if given file extension is supported by this rule
-    #
-    #   @param  FileExt     The extension of a file
-    #
-    #   @retval True        If the extension is supported
-    #   @retval False       If the extension is not supported
-    #
-    def IsSupported(self, FileExt):
-        return FileExt in self.SourceFileExtList
-
     def Instantiate(self, Macros={}):
         NewRuleObject = copy.copy(self)
         NewRuleObject.BuildTargets = {}
@@ -365,8 +354,8 @@ class BuildRule:
         self._State = ""
         self._RuleInfo = tdict(True, 2)     # {toolchain family : {"InputFile": {}, "OutputFile" : [], "Command" : []}}
         self._FileType = ''
-        self._BuildTypeList = []
-        self._ArchList = []
+        self._BuildTypeList = set()
+        self._ArchList = set()
         self._FamilyList = []
         self._TotalToolChainFamilySet = set()
         self._RuleObjectList = [] # FileBuildRule object list
@@ -456,8 +445,8 @@ class BuildRule:
     #
     def ParseSectionHeader(self, LineIndex):
         self._RuleInfo = tdict(True, 2)
-        self._BuildTypeList = []
-        self._ArchList = []
+        self._BuildTypeList = set()
+        self._ArchList = set()
         self._FamilyList = []
         self._TotalToolChainFamilySet = set()
         FileType = ''
@@ -494,10 +483,8 @@ class BuildRule:
                     BuildType = TokenList[1]
                 if len(TokenList) > 2:
                     Arch = TokenList[2]
-            if BuildType not in self._BuildTypeList:
-                self._BuildTypeList.append(BuildType)
-            if Arch not in self._ArchList:
-                self._ArchList.append(Arch)
+            self._BuildTypeList.add(BuildType)
+            self._ArchList.add(Arch)
 
         if 'COMMON' in self._BuildTypeList and len(self._BuildTypeList) > 1:
             EdkLogger.error("build", FORMAT_INVALID,
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 13/14] BaseTools: GenC - move content from both parts of if/else
  2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
                   ` (11 preceding siblings ...)
  2018-04-05 23:14 ` [PATCH v1 12/14] BaseTools: change more list to set Jaben Carsey
@ 2018-04-05 23:14 ` Jaben Carsey
  2018-04-05 23:14 ` [PATCH v1 14/14] BaseTools: refactor and remove out of date use of .keys() Jaben Carsey
  2018-04-10  1:53 ` [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Zhu, Yonghong
  14 siblings, 0 replies; 16+ messages in thread
From: Jaben Carsey @ 2018-04-05 23:14 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

move identical lines out of both if and else and move 1 level up.

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>
---
 BaseTools/Source/Python/AutoGen/GenC.py | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Python/AutoGen/GenC.py
index 4d9ea1b2a8b1..f10ed5dbbe36 100644
--- a/BaseTools/Source/Python/AutoGen/GenC.py
+++ b/BaseTools/Source/Python/AutoGen/GenC.py
@@ -1136,16 +1136,14 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
             #
             # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.
             #
+            AutoGenH.Append('#define %s  %s%s\n' %(PcdValueName, Type, PcdVariableName))
             if Unicode:
-                AutoGenH.Append('#define %s  %s%s\n' %(PcdValueName, Type, PcdVariableName))
                 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))
                 AutoGenH.Append('extern %s UINT16 %s%s;\n' %(Const, PcdVariableName, Array))
-                AutoGenH.Append('#define %s  %s%s\n' %(GetModeName, Type, PcdVariableName))
             else:
-                AutoGenH.Append('#define %s  %s%s\n' %(PcdValueName, Type, PcdVariableName))
                 AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))
                 AutoGenH.Append('extern %s UINT8 %s%s;\n' %(Const, PcdVariableName, Array))
-                AutoGenH.Append('#define %s  %s%s\n' %(GetModeName, Type, PcdVariableName))
+            AutoGenH.Append('#define %s  %s%s\n' %(GetModeName, Type, PcdVariableName))
                 
             PcdDataSize = GetPcdSize(Pcd)
             if Pcd.Type == TAB_PCDS_FIXED_AT_BUILD:
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v1 14/14] BaseTools: refactor and remove out of date use of .keys()
  2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
                   ` (12 preceding siblings ...)
  2018-04-05 23:14 ` [PATCH v1 13/14] BaseTools: GenC - move content from both parts of if/else Jaben Carsey
@ 2018-04-05 23:14 ` Jaben Carsey
  2018-04-10  1:53 ` [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Zhu, Yonghong
  14 siblings, 0 replies; 16+ messages in thread
From: Jaben Carsey @ 2018-04-05 23:14 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

this is no longer required to make dictionary objects iterable.

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>
---
 BaseTools/Scripts/SmiHandlerProfileSymbolGen.py           | 4 ++--
 BaseTools/Source/Python/AutoGen/GenMake.py                | 2 +-
 BaseTools/Source/Python/GenFds/Fv.py                      | 2 +-
 BaseTools/Source/Python/GenFds/Section.py                 | 5 +----
 BaseTools/Source/Python/TargetTool/TargetTool.py          | 3 +--
 BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py | 5 +----
 BaseTools/Source/Python/build/build.py                    | 4 +---
 7 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/BaseTools/Scripts/SmiHandlerProfileSymbolGen.py b/BaseTools/Scripts/SmiHandlerProfileSymbolGen.py
index f03278b64f8f..26c092410386 100644
--- a/BaseTools/Scripts/SmiHandlerProfileSymbolGen.py
+++ b/BaseTools/Scripts/SmiHandlerProfileSymbolGen.py
@@ -204,7 +204,7 @@ def genGuidString(guidreffile):
         if len(guidLineList) == 2:
             guid = guidLineList[0]
             guidName = guidLineList[1]
-            if guid not in dictGuid.keys() :
+            if guid not in dictGuid :
                 dictGuid[guid] = guidName
 
 def createSym(symbolName):
@@ -256,7 +256,7 @@ def main():
         for smiEntry in SmiEntry:
             if smiEntry.hasAttribute("HandlerType"):
                 guidValue = smiEntry.getAttribute("HandlerType")
-                if guidValue in dictGuid.keys() :
+                if guidValue in dictGuid:
                     smiEntry.setAttribute("HandlerType", dictGuid[guidValue])
             SmiHandler = smiEntry.getElementsByTagName("SmiHandler")
             for smiHandler in SmiHandler:
diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py
index dcdfcca1a5b0..61432516fd26 100644
--- a/BaseTools/Source/Python/AutoGen/GenMake.py
+++ b/BaseTools/Source/Python/AutoGen/GenMake.py
@@ -491,7 +491,7 @@ cleanlib:
             ImageEntryPoint = "_ModuleEntryPoint"
 
         for k, v in self._AutoGenObject.Module.Defines.iteritems():
-            if k not in self._AutoGenObject.Macros.keys():
+            if k not in self._AutoGenObject.Macros:
                 self._AutoGenObject.Macros[k] = v
 
         if 'MODULE_ENTRY_POINT' not in self._AutoGenObject.Macros.keys():
diff --git a/BaseTools/Source/Python/GenFds/Fv.py b/BaseTools/Source/Python/GenFds/Fv.py
index 14e36b885966..345ad3bdcc90 100644
--- a/BaseTools/Source/Python/GenFds/Fv.py
+++ b/BaseTools/Source/Python/GenFds/Fv.py
@@ -318,7 +318,7 @@ class FV (FvClassObject):
                                           ' %s' %ErasePloarity    + \
                                           T_CHAR_LF)
         if not (self.FvAttributeDict is None):
-            for FvAttribute in self.FvAttributeDict.keys() :
+            for FvAttribute in self.FvAttributeDict:
                 if FvAttribute == "FvUsedSizeEnable":
                     if self.FvAttributeDict[FvAttribute].upper() in ('TRUE', '1') :
                         self.UsedSizeEnable = True
diff --git a/BaseTools/Source/Python/GenFds/Section.py b/BaseTools/Source/Python/GenFds/Section.py
index 5e0b4bee7d1c..6335c249a693 100644
--- a/BaseTools/Source/Python/GenFds/Section.py
+++ b/BaseTools/Source/Python/GenFds/Section.py
@@ -111,10 +111,7 @@ class Section (SectionClassObject):
     #   @retval tuple       (File list, boolean)
     #
     def GetFileList(FfsInf, FileType, FileExtension, Dict = {}, IsMakefile=False):
-        if FileType in Section.SectFileType.keys() :
-            IsSect = True
-        else :
-            IsSect = False
+        IsSect = FileType in Section.SectFileType
 
         if FileExtension is not None:
             Suffix = FileExtension
diff --git a/BaseTools/Source/Python/TargetTool/TargetTool.py b/BaseTools/Source/Python/TargetTool/TargetTool.py
index ede9713c9b8b..143b53ec35ef 100644
--- a/BaseTools/Source/Python/TargetTool/TargetTool.py
+++ b/BaseTools/Source/Python/TargetTool/TargetTool.py
@@ -80,9 +80,8 @@ class TargetTool():
             traceback.print_exception(last_type, last_value, last_tb)
 
     def Print(self):
-        KeyList = self.TargetTxtDictionary.keys()
         errMsg  = ''
-        for Key in KeyList:
+        for Key in self.TargetTxtDictionary:
             if type(self.TargetTxtDictionary[Key]) == type([]):
                 print "%-30s = %s" % (Key, ''.join(elem + ' ' for elem in self.TargetTxtDictionary[Key]))
             elif self.TargetTxtDictionary[Key] is None:
diff --git a/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py b/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py
index e37a0b6c3be7..165ac111272a 100644
--- a/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py
+++ b/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py
@@ -486,10 +486,7 @@ class InfPomAlignment(ModuleObject):
             #
             # Get all LibraryClasses
             #
-            LibClassObj = self.Parser.InfLibraryClassSection.LibraryClasses
-            Keys = LibClassObj.keys()
-            for Key in Keys:
-                LibraryClassData = LibClassObj[Key]
+            for LibraryClassData in self.Parser.InfLibraryClassSection.LibraryClasses.values():
                 for Item in LibraryClassData:
                     LibraryClass = CommonObject.LibraryClassObject()
                     LibraryClass.SetUsage(DT.USAGE_ITEM_CONSUMES)
diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Python/build/build.py
index f211f8c64116..ceacc124933c 100644
--- a/BaseTools/Source/Python/build/build.py
+++ b/BaseTools/Source/Python/build/build.py
@@ -1421,9 +1421,7 @@ class Build():
     def _RebaseModule (self, MapBuffer, BaseAddress, ModuleList, AddrIsOffset = True, ModeIsSmm = False):
         if ModeIsSmm:
             AddrIsOffset = False
-        InfFileNameList = ModuleList.keys()
-        #InfFileNameList.sort()
-        for InfFile in InfFileNameList:
+        for InfFile in ModuleList:
             sys.stdout.write (".")
             sys.stdout.flush()
             ModuleInfo = ModuleList[InfFile]
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity
  2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
                   ` (13 preceding siblings ...)
  2018-04-05 23:14 ` [PATCH v1 14/14] BaseTools: refactor and remove out of date use of .keys() Jaben Carsey
@ 2018-04-10  1:53 ` Zhu, Yonghong
  14 siblings, 0 replies; 16+ messages in thread
From: Zhu, Yonghong @ 2018-04-10  1:53 UTC (permalink / raw)
  To: Carsey, Jaben, edk2-devel@lists.01.org

Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com> 

Best Regards,
Zhu Yonghong

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jaben Carsey
Sent: Friday, April 06, 2018 7:14 AM
To: edk2-devel@lists.01.org
Subject: [edk2] [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity

group of changes to make code smaller and reduce overhead.

Jaben Carsey (14):
  BaseTools: remove unused file
  BaseTools: remove uncalled functions
  BaseTools: defaultdict(set) allows us to just add to the set
  BaseTools: sets are faster to check via "in" due to hashing
  BaseTools: replace a dict with a set
  BaseTools: remove unused variables
  BaseTools: change list to set
  BaseTools: simplify testing for existance and containing data
  BaseTools: optimize buildoptions loop
  BaseTools: change another list to set
  BaseTools: remove unneeded function call
  BaseTools: change more list to set
  BaseTools: GenC - move content from both parts of if/else
  BaseTools: refactor and remove out of date use of .keys()

 BaseTools/Scripts/SmiHandlerProfileSymbolGen.py           |   4 +-
 BaseTools/Source/Python/AutoGen/AutoGen.py                | 101 +++++++-------------
 BaseTools/Source/Python/AutoGen/BuildEngine.py            |  29 ++----
 BaseTools/Source/Python/AutoGen/GenC.py                   |   6 +-
 BaseTools/Source/Python/AutoGen/GenMake.py                |   2 +-
 BaseTools/Source/Python/Common/Dictionary.py              |  76 ---------------
 BaseTools/Source/Python/Common/TargetTxtClassObject.py    |  27 ------
 BaseTools/Source/Python/Common/ToolDefClassObject.py      |   7 +-
 BaseTools/Source/Python/GenFds/Fv.py                      |   2 +-
 BaseTools/Source/Python/GenFds/Section.py                 |   5 +-
 BaseTools/Source/Python/TargetTool/TargetTool.py          |   3 +-
 BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py |   5 +-
 BaseTools/Source/Python/build/build.py                    |   4 +-
 13 files changed, 59 insertions(+), 212 deletions(-)  delete mode 100644 BaseTools/Source/Python/Common/Dictionary.py

--
2.16.2.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2018-04-10  1:53 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-05 23:13 [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Jaben Carsey
2018-04-05 23:13 ` [PATCH v1 01/14] BaseTools: remove unused file Jaben Carsey
2018-04-05 23:13 ` [PATCH v1 02/14] BaseTools: remove uncalled functions Jaben Carsey
2018-04-05 23:13 ` [PATCH v1 03/14] BaseTools: defaultdict(set) allows us to just add to the set Jaben Carsey
2018-04-05 23:13 ` [PATCH v1 04/14] BaseTools: sets are faster to check via "in" due to hashing Jaben Carsey
2018-04-05 23:13 ` [PATCH v1 05/14] BaseTools: replace a dict with a set Jaben Carsey
2018-04-05 23:13 ` [PATCH v1 06/14] BaseTools: remove unused variables Jaben Carsey
2018-04-05 23:13 ` [PATCH v1 07/14] BaseTools: change list to set Jaben Carsey
2018-04-05 23:13 ` [PATCH v1 08/14] BaseTools: simplify testing for existance and containing data Jaben Carsey
2018-04-05 23:13 ` [PATCH v1 09/14] BaseTools: optimize buildoptions loop Jaben Carsey
2018-04-05 23:13 ` [PATCH v1 10/14] BaseTools: change another list to set Jaben Carsey
2018-04-05 23:13 ` [PATCH v1 11/14] BaseTools: remove unneeded function call Jaben Carsey
2018-04-05 23:14 ` [PATCH v1 12/14] BaseTools: change more list to set Jaben Carsey
2018-04-05 23:14 ` [PATCH v1 13/14] BaseTools: GenC - move content from both parts of if/else Jaben Carsey
2018-04-05 23:14 ` [PATCH v1 14/14] BaseTools: refactor and remove out of date use of .keys() Jaben Carsey
2018-04-10  1:53 ` [PATCH v1 00/14] BaseTools: refactoring the code for readability and simplicity Zhu, Yonghong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox