summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python
diff options
context:
space:
mode:
authorCarsey, Jaben <jaben.carsey@intel.com>2018-04-27 22:04:14 +0800
committerYonghong Zhu <yonghong.zhu@intel.com>2018-05-02 14:53:42 +0800
commit50874612be60df3752327fb488799074826b759e (patch)
tree7ddbedbe745e18aa088a611d8e88b3b40d815153 /BaseTools/Source/Python
parenta802b269061cf83c17b74dc166cf21efe25f938f (diff)
downloadedk2-50874612be60df3752327fb488799074826b759e.tar.gz
edk2-50874612be60df3752327fb488799074826b759e.tar.bz2
edk2-50874612be60df3752327fb488799074826b759e.zip
BaseTools: Workspace/MetaFileParser - refactor dicts
make defaultdict to avoid initialize inner items to empty the dict, call clear instead of making a new object v2 - to empty the dict, dont re-run constructor, just call .clear() in post process API also. 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>
Diffstat (limited to 'BaseTools/Source/Python')
-rw-r--r--BaseTools/Source/Python/Workspace/MetaFileParser.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py
index 788eca1761..64394026cb 100644
--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
@@ -31,7 +31,7 @@ from Common.Misc import GuidStructureStringToGuidString, CheckPcdDatum, PathClas
from Common.Expression import *
from CommonDataClass.Exceptions import *
from Common.LongFilePathSupport import OpenLongFilePath as open
-
+from collections import defaultdict
from MetaFileTable import MetaFileStorage
from MetaFileCommentParser import CheckInfComment
@@ -163,7 +163,7 @@ class MetaFileParser(object):
self._FileDir = self.MetaFile.Dir
self._Defines = {}
self._FileLocalMacros = {}
- self._SectionsMacroDict = {}
+ self._SectionsMacroDict = defaultdict(dict)
# for recursive parsing
self._Owner = [Owner]
@@ -421,17 +421,16 @@ class MetaFileParser(object):
def _ConstructSectionMacroDict(self, Name, Value):
ScopeKey = [(Scope[0], Scope[1],Scope[2]) for Scope in self._Scope]
ScopeKey = tuple(ScopeKey)
- SectionDictKey = self._SectionType, ScopeKey
#
# DecParser SectionType is a list, will contain more than one item only in Pcd Section
# As Pcd section macro usage is not alllowed, so here it is safe
#
if type(self) == DecParser:
SectionDictKey = self._SectionType[0], ScopeKey
- if SectionDictKey not in self._SectionsMacroDict:
- self._SectionsMacroDict[SectionDictKey] = {}
- SectionLocalMacros = self._SectionsMacroDict[SectionDictKey]
- SectionLocalMacros[Name] = Value
+ else:
+ SectionDictKey = self._SectionType, ScopeKey
+
+ self._SectionsMacroDict[SectionDictKey][Name] = Value
## Get section Macros that are applicable to current line, which may come from other sections
## that share the same name while scope is wider
@@ -936,7 +935,7 @@ class DscParser(MetaFileParser):
self._SubsectionType = MODEL_UNKNOWN
self._SubsectionName = ''
self._Owner[-1] = -1
- OwnerId = {}
+ OwnerId.clear()
continue
# subsection header
elif Line[0] == TAB_OPTION_START and Line[-1] == TAB_OPTION_END:
@@ -1296,7 +1295,7 @@ class DscParser(MetaFileParser):
self._DirectiveEvalStack = []
self._FileWithError = self.MetaFile
self._FileLocalMacros = {}
- self._SectionsMacroDict = {}
+ self._SectionsMacroDict.clear()
GlobalData.gPlatformDefines = {}
# Get all macro and PCD which has straitforward value