From: Jaben Carsey <jaben.carsey@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>, Yonghong Zhu <yonghong.zhu@intel.com>
Subject: [PATCH v2 11/27] BaseTools: Workspace/MetaFileParser - refactor dicts
Date: Fri, 27 Apr 2018 07:04:14 -0700 [thread overview]
Message-ID: <232ef778f47d1c3b2f0533e2dcce1e1b4bafe710.1524837706.git.jaben.carsey@intel.com> (raw)
In-Reply-To: <cover.1524837705.git.jaben.carsey@intel.com>
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>
---
BaseTools/Source/Python/Workspace/MetaFileParser.py | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py
index 550359f9abb2..51126d710b2b 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
--
2.16.2.windows.1
next parent reply other threads:[~2018-04-27 14:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1524837705.git.jaben.carsey@intel.com>
2018-04-27 14:04 ` Jaben Carsey [this message]
2018-05-02 6:44 ` [PATCH v2 11/27] BaseTools: Workspace/MetaFileParser - refactor dicts Zhu, Yonghong
2018-04-27 14:04 ` [PATCH v3 16/27] BaseTools: Replace EDK Component strings with predefined constant Jaben Carsey
2018-05-02 6:45 ` Zhu, Yonghong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=232ef778f47d1c3b2f0533e2dcce1e1b4bafe710.1524837706.git.jaben.carsey@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox