From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.136; helo=mga12.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1792220352138 for ; Tue, 1 May 2018 23:44:42 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 May 2018 23:44:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,353,1520924400"; d="scan'208";a="36183985" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga007.fm.intel.com with ESMTP; 01 May 2018 23:44:42 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 1 May 2018 23:44:42 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.210]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.240]) with mapi id 14.03.0319.002; Wed, 2 May 2018 14:44:39 +0800 From: "Zhu, Yonghong" To: "Carsey, Jaben" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [PATCH v2 11/27] BaseTools: Workspace/MetaFileParser - refactor dicts Thread-Index: AQHT3jCmbHIKk00XqkGuEWBT0sri46QcBZ0Q Date: Wed, 2 May 2018 06:44:38 +0000 Message-ID: References: <232ef778f47d1c3b2f0533e2dcce1e1b4bafe710.1524837706.git.jaben.carsey@intel.com> In-Reply-To: <232ef778f47d1c3b2f0533e2dcce1e1b4bafe710.1524837706.git.jaben.carsey@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v2 11/27] BaseTools: Workspace/MetaFileParser - refactor dicts X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 May 2018 06:44:43 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Yonghong Zhu =20 Best Regards, Zhu Yonghong -----Original Message----- From: Carsey, Jaben=20 Sent: Friday, April 27, 2018 10:04 PM To: edk2-devel@lists.01.org Cc: Gao, Liming ; Zhu, Yonghong Subject: [PATCH v2 11/27] BaseTools: Workspace/MetaFileParser - refactor di= cts make defaultdict to avoid initialize inner items to empty the dict, call cl= ear 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 Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/Workspace/MetaFileParser.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTool= s/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 CommonDataCl= ass.Exceptions import * from Common.LongFilePathSupport import OpenLongFil= ePath as open - +from collections import defaultdict from MetaFileTable import MetaFileStorage from MetaFileCommentParser impo= rt CheckInfComment =20 @@ -163,7 +163,7 @@ class MetaFileParser(object): self._FileDir =3D self.MetaFile.Dir self._Defines =3D {} self._FileLocalMacros =3D {} - self._SectionsMacroDict =3D {} + self._SectionsMacroDict =3D defaultdict(dict) =20 # for recursive parsing self._Owner =3D [Owner] @@ -421,17 +421,16 @@ class MetaFileParser(object): def _ConstructSectionMacroDict(self, Name, Value): ScopeKey =3D [(Scope[0], Scope[1],Scope[2]) for Scope in self._Sco= pe] ScopeKey =3D tuple(ScopeKey) - SectionDictKey =3D 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) =3D=3D DecParser: SectionDictKey =3D self._SectionType[0], ScopeKey - if SectionDictKey not in self._SectionsMacroDict: - self._SectionsMacroDict[SectionDictKey] =3D {} - SectionLocalMacros =3D self._SectionsMacroDict[SectionDictKey] - SectionLocalMacros[Name] =3D Value + else: + SectionDictKey =3D self._SectionType, ScopeKey + + self._SectionsMacroDict[SectionDictKey][Name] =3D Value =20 ## Get section Macros that are applicable to current line, which may c= ome from other sections=20 ## that share the same name while scope is wider @@ -936,7 +935,7 @@ c= lass DscParser(MetaFileParser): self._SubsectionType =3D MODEL_UNKNOWN self._SubsectionName =3D '' self._Owner[-1] =3D -1 - OwnerId =3D {} + OwnerId.clear() continue # subsection header elif Line[0] =3D=3D TAB_OPTION_START and Line[-1] =3D=3D TAB_O= PTION_END: @@ -1296,7 +1295,7 @@ class DscParser(MetaFileParser): self._DirectiveEvalStack =3D [] self._FileWithError =3D self.MetaFile self._FileLocalMacros =3D {} - self._SectionsMacroDict =3D {} + self._SectionsMacroDict.clear() GlobalData.gPlatformDefines =3D {} =20 # Get all macro and PCD which has straitforward value -- 2.16.2.windows.1