From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 1223222690AD7 for ; Wed, 18 Apr 2018 07:22:56 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Apr 2018 07:22:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,465,1517904000"; d="scan'208";a="44258243" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga003.jf.intel.com with ESMTP; 18 Apr 2018 07:22:56 -0700 Received: from fmsmsx124.amr.corp.intel.com (10.18.125.39) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 18 Apr 2018 07:22:56 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx124.amr.corp.intel.com (10.18.125.39) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 18 Apr 2018 07:22:56 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.210]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.6]) with mapi id 14.03.0319.002; Wed, 18 Apr 2018 22:22:53 +0800 From: "Zhu, Yonghong" To: "Carsey, Jaben" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [PATCH v2 1/3] BaseTools: refactor and remove more keys() usage Thread-Index: AQHT1yCdWjf1Y5kZu0m+E/AUJhYOW6QGkx5A Date: Wed, 18 Apr 2018 14:22:52 +0000 Message-ID: References: <144204ad5148ab81c5d9be604b0cc8abf2bff7b5.1524061167.git.jaben.carsey@intel.com> In-Reply-To: <144204ad5148ab81c5d9be604b0cc8abf2bff7b5.1524061167.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 1/3] BaseTools: refactor and remove more keys() usage 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, 18 Apr 2018 14:22:57 -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: Wednesday, April 18, 2018 10:22 PM To: edk2-devel@lists.01.org Cc: Gao, Liming ; Zhu, Yonghong Subject: [PATCH v2 1/3] BaseTools: refactor and remove more keys() usage this is no longer required to make dictionary objects iterable. v2 - add back a missing "C" PcdName -> PcdCName Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/Workspace/DscBuildData.py | 59 +++++++++----------= - 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/= Source/Python/Workspace/DscBuildData.py index f50059551e2e..16748f8d457d 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -594,7 +594,7 @@ class DscBuildData(PlatformBuildClassObject): # # If command line defined, should override the value in DSC file. # - if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData.gCommandLineDefines= .keys(): + if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData.gCommandLineDefines= : try: self._LoadFixAddress =3D int(GlobalData.gCommandLineDefine= s['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0) except: @@ -682,9 +682,7 @@ class DscBuildData(PlatformBuildClassObject): self.DefaultStores[Record[1].upper()] =3D (DscBuildData.To= Int(Record[0]),Record[1].upper()) if TAB_DEFAULT_STORES_DEFAULT not in self.DefaultStores: self.DefaultStores[TAB_DEFAULT_STORES_DEFAULT] =3D (0,TAB_= DEFAULT_STORES_DEFAULT) - GlobalData.gDefaultStores =3D self.DefaultStores.keys() - if GlobalData.gDefaultStores: - GlobalData.gDefaultStores.sort() + GlobalData.gDefaultStores =3D=20 + sorted(self.DefaultStores.keys()) return self.DefaultStores =20 ## Retrieve [Components] section information @@ -1423,11 +1421,11 @@ c= lass DscBuildData(PlatformBuildClassObject): =20 for pcdkey in Pcds: pcd =3D Pcds[pcdkey] - if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in= pcd.SkuInfoList.keys(): + if 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' in pcd.Sk= uInfoList: pcd.SkuInfoList['DEFAULT'] =3D pcd.SkuInfoList['COMMON= '] - del(pcd.SkuInfoList['COMMON']) - elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in p= cd.SkuInfoList.keys(): - del(pcd.SkuInfoList['COMMON']) + del pcd.SkuInfoList['COMMON'] + elif 'DEFAULT' in pcd.SkuInfoList and 'COMMON' in pcd.SkuI= nfoList: + del pcd.SkuInfoList['COMMON'] =20 map(self.FilterSkuSettings,[Pcds[pcdkey] for pcdkey in Pcds if Pcd= s[pcdkey].Type in DynamicPcdType]) return Pcds @@ -1472,10 +1470,7 @@ class DscBuildData(PlatformBuildClassObject): else: PcdValueDict[PcdCName, TokenSpaceGuid] =3D {SkuName:(PcdVa= lue, DatumType, MaxDatumSize)} =20 - PcdsKeys =3D PcdValueDict.keys() - for PcdCName, TokenSpaceGuid in PcdsKeys: - - PcdSetting =3D PcdValueDict[PcdCName, TokenSpaceGuid] + for ((PcdCName,TokenSpaceGuid),PcdSetting) in PcdValueDict.iterite= ms(): PcdValue =3D None DatumType =3D None MaxDatumSize =3D None @@ -1872,7 +1867,7 @@ class DscBuildData(PlatformBuildClassObject): OverrideValues =3D {DefaultStore:""} if Pcd.SkuOverrideValues: OverrideValues =3D Pcd.SkuOverrideValues[SkuName] - for DefaultStoreName in OverrideValues.keys(): + for DefaultStoreName in OverrideValues: CApp =3D CApp + 'void\n' CApp =3D CApp + 'Initialize_%s_%s_%s_%s(\n' % (SkuName, Defaul= tStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName) CApp =3D CApp + ' void\n' @@ -2251,7 +2246,7 @@ class DscBuildData(PlatformBuildClassObject): =20 PcdValue, DatumType, MaxDatumSize =3D self._ValidatePcd(PcdCNa= me, TokenSpaceGuid, Setting, Type, Dummy4) SkuInfo =3D SkuInfoClass(SkuName, self.SkuIds[SkuName][0], '',= '', '', '', '', PcdValue) - if (PcdCName, TokenSpaceGuid) in Pcds.keys(): + if (PcdCName, TokenSpaceGuid) in Pcds: pcdObject =3D Pcds[PcdCName, TokenSpaceGuid] pcdObject.SkuInfoList[SkuName] =3D SkuInfo if MaxDatumSize.strip(): @@ -2284,15 +2279,15 @@ class DscBuildData(PlatformBuildClassObject): for sku in pcd.SkuInfoList.values(): if not sku.DefaultValue: sku.DefaultValue =3D pcdDecObject.DefaultValue - if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in= pcd.SkuInfoList.keys(): + if 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' not in pcd.Sk= uInfoList: valuefromDec =3D pcdDecObject.DefaultValue SkuInfo =3D SkuInfoClass('DEFAULT', '0', '', '', '', '', '= ', valuefromDec) pcd.SkuInfoList['DEFAULT'] =3D SkuInfo - elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in p= cd.SkuInfoList.keys(): + elif 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' in pcd.SkuI= nfoList: pcd.SkuInfoList['DEFAULT'] =3D pcd.SkuInfoList['COMMON'] - del(pcd.SkuInfoList['COMMON']) - elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.S= kuInfoList.keys(): - del(pcd.SkuInfoList['COMMON']) + del pcd.SkuInfoList['COMMON'] + elif 'DEFAULT' in pcd.SkuInfoList and 'COMMON' in pcd.SkuInfoL= ist: + del pcd.SkuInfoList['COMMON'] =20 map(self.FilterSkuSettings,Pcds.values()) =20 @@ -2301,7 +2296,7 @@ class DscBuildData(PlatformBuildClassObject): def FilterSkuSettings(self, PcdObj): =20 if self.SkuIdMgr.SkuUsageType =3D=3D self.SkuIdMgr.SINGLE: - if 'DEFAULT' in PcdObj.SkuInfoList.keys() and self.SkuIdMgr.Sy= stemSkuId not in PcdObj.SkuInfoList.keys(): + if 'DEFAULT' in PcdObj.SkuInfoList and self.SkuIdMgr.SystemSku= Id not in PcdObj.SkuInfoList: PcdObj.SkuInfoList[self.SkuIdMgr.SystemSkuId] =3D PcdObj.S= kuInfoList['DEFAULT'] PcdObj.SkuInfoList =3D {'DEFAULT':PcdObj.SkuInfoList[self.SkuI= dMgr.SystemSkuId]} PcdObj.SkuInfoList['DEFAULT'].SkuIdName =3D 'DEFAULT' @@ -2456,7 +2451,7 @@ class DscBuildData(PlatformBuildClassObject): EdkLogger.error('Build', PCD_VARIABLE_ATTRIBUTES_CONFL= ICT_ERROR, "The variable %s.%s for DynamicHii PCDs has conflicting attribut= es [%s] and [%s] " % (VariableGuid, VariableName, VarAttribute, VariableAtt= rs[(VariableName, VariableGuid)])) =20 pcdDecObject =3D self._DecPcds[PcdCName, TokenSpaceGuid] - if (PcdCName, TokenSpaceGuid) in Pcds.keys(): + if (PcdCName, TokenSpaceGuid) in Pcds: pcdObject =3D Pcds[PcdCName, TokenSpaceGuid] if SkuName in pcdObject.SkuInfoList: Skuitem =3D pcdObject.SkuInfoList[SkuName] @@ -2494,15= +2489,15 @@ class DscBuildData(PlatformBuildClassObject): for default_store in sku.DefaultStoreDict: sku.DefaultStoreDict[default_store]=3DpcdDecObject= .DefaultValue pcd.DefaultValue =3D pcdDecObject.DefaultValue - if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in= pcd.SkuInfoList.keys(): + if 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' not in pcd.Sk= uInfoList: valuefromDec =3D pcdDecObject.DefaultValue SkuInfo =3D SkuInfoClass('DEFAULT', '0', SkuInfoObj.Variab= leName, SkuInfoObj.VariableGuid, SkuInfoObj.VariableOffset, valuefromDec,Va= riableAttribute=3DSkuInfoObj.VariableAttribute,DefaultStore=3D{DefaultStore= :valuefromDec}) pcd.SkuInfoList['DEFAULT'] =3D SkuInfo - elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in p= cd.SkuInfoList.keys(): + elif 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' in pcd.SkuI= nfoList: pcd.SkuInfoList['DEFAULT'] =3D pcd.SkuInfoList['COMMON'] - del(pcd.SkuInfoList['COMMON']) - elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.S= kuInfoList.keys(): - del(pcd.SkuInfoList['COMMON']) + del pcd.SkuInfoList['COMMON'] + elif 'DEFAULT' in pcd.SkuInfoList and 'COMMON' in pcd.SkuInfoL= ist: + del pcd.SkuInfoList['COMMON'] =20 if pcd.MaxDatumSize.strip(): MaxSize =3D int(pcd.MaxDatumSize, 0) @@ -2584,7 +2579,7 @@= class DscBuildData(PlatformBuildClassObject): # VpdOffset, MaxDatumSize, InitialValue =3D self._ValidatePcd(Pc= dCName, TokenSpaceGuid, Setting, Type, Dummy4) SkuInfo =3D SkuInfoClass(SkuName, self.SkuIds[SkuName][0], '',= '', '', '', VpdOffset, InitialValue) - if (PcdCName, TokenSpaceGuid) in Pcds.keys(): + if (PcdCName, TokenSpaceGuid) in Pcds: pcdObject =3D Pcds[PcdCName, TokenSpaceGuid] pcdObject.SkuInfoList[SkuName] =3D SkuInfo if MaxDatumSize.strip(): @@ -2618,15 +2613,15 @@ class DscBuildData(PlatformBuildClassObject): for sku in pcd.SkuInfoList.values(): if not sku.DefaultValue: sku.DefaultValue =3D pcdDecObject.DefaultValue - if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in= pcd.SkuInfoList.keys(): + if 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' not in pcd.Sk= uInfoList: valuefromDec =3D pcdDecObject.DefaultValue SkuInfo =3D SkuInfoClass('DEFAULT', '0', '', '', '', '', S= kuInfoObj.VpdOffset, valuefromDec) pcd.SkuInfoList['DEFAULT'] =3D SkuInfo - elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in p= cd.SkuInfoList.keys(): + elif 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' in pcd.SkuI= nfoList: pcd.SkuInfoList['DEFAULT'] =3D pcd.SkuInfoList['COMMON'] - del(pcd.SkuInfoList['COMMON']) - elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.S= kuInfoList.keys(): - del(pcd.SkuInfoList['COMMON']) + del pcd.SkuInfoList['COMMON'] + elif 'DEFAULT' in pcd.SkuInfoList and 'COMMON' in pcd.SkuInfoL= ist: + del pcd.SkuInfoList['COMMON'] =20 =20 map(self.FilterSkuSettings,Pcds.values()) -- 2.16.2.windows.1