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.151; helo=mga17.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 DEFDE20352138 for ; Tue, 1 May 2018 23:49:08 -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 fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 May 2018 23:49:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,353,1520924400"; d="scan'208";a="36184931" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga007.fm.intel.com with ESMTP; 01 May 2018 23:49:08 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 1 May 2018 23:49:08 -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:49:05 +0800 From: "Zhu, Yonghong" To: "Carsey, Jaben" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [PATCH v1 22/27] BaseTools: remove redundant if comparison Thread-Index: AQHT2L+I8LU8Ij5M/0a4XggKkJOLoKQcEc7A Date: Wed, 2 May 2018 06:49:04 +0000 Message-ID: References: In-Reply-To: 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 v1 22/27] BaseTools: remove redundant if comparison 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:49:09 -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 20, 2018 11:52 PM To: edk2-devel@lists.01.org Cc: Gao, Liming ; Zhu, Yonghong Subject: [PATCH v1 22/27] BaseTools: remove redundant if comparison inherently python will check string and list for None and having data if in [None, ''] and similar are superflous. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/AutoGen/AutoGen.py | 26 ++++++++------= -- BaseTools/Source/Python/AutoGen/GenC.py | 2 +- BaseTools/Source/Python/GenFds/FfsInfStatement.py | 4 +-- BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py | 32 ++++++++++----= ------ BaseTools/Source/Python/Workspace/DscBuildData.py | 8 ++--- BaseTools/Source/Python/Workspace/InfBuildData.py | 2 +- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/= Python/AutoGen/AutoGen.py index 534fbe79fad9..871afedcde4b 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -420,14 +420,14 @@ class WorkspaceAutoGen(AutoGen): if BuildData.Pcds[key].Pending: if key in Platform.Pcds: PcdInPlatform =3D Platform.Pcds[key] - if PcdInPlatform.Type not in [None, '']: + if PcdInPlatform.Type: BuildData.Pcds[key].Type =3D PcdInPlat= form.Type =20 if BuildData.MetaFile in Platform.Modules: PlatformModule =3D Platform.Modules[str(Bu= ildData.MetaFile)] if key in PlatformModule.Pcds: PcdInPlatform =3D PlatformModule.Pcds[= key] - if PcdInPlatform.Type not in [None, ''= ]: + if PcdInPlatform.Type: BuildData.Pcds[key].Type =3D PcdIn= Platform.Type =20 if TAB_PCDS_DYNAMIC_EX in BuildData.Pcds[key].Type= : @@ -1394,7 +1394,7 @@ class PlatformAutoGen(AutoGen): =20 for PcdFromModule in M.ModulePcdList + M.LibraryPcdList: # make sure that the "VOID*" kind of datum has MaxDatumSiz= e set - if PcdFromModule.DatumType =3D=3D "VOID*" and PcdFromModul= e.MaxDatumSize in [None, '']: + if PcdFromModule.DatumType =3D=3D "VOID*" and not PcdFromM= odule.MaxDatumSize: NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.T= okenSpaceGuidCName, PcdFromModule.TokenCName, F)) =20 # Check the PCD from Binary INF or Source INF @@ -1471,7 += 1471,7 @@ class PlatformAutoGen(AutoGen): ExtraData=3D"\n\tExisted %s PCD %s= in:\n\t\t%s\n" % (PcdFromModule.Type, PcdFromModu= le.TokenCName, InfName)) # make sure that the "VOID*" kind of datum has MaxDatu= mSize set - if PcdFromModule.DatumType =3D=3D "VOID*" and PcdFromM= odule.MaxDatumSize in [None, '']: + if PcdFromModule.DatumType =3D=3D "VOID*" and not PcdF= romModule.MaxDatumSize: NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModu= le.TokenSpaceGuidCName, PcdFromModule.TokenCName, InfName)) if M.ModuleType in SUP_MODULE_SET_PEI: PcdFromModule.Phase =3D "PEI" @@ -1999,7 +1999,7 @@ class PlatformAutoGen(AutoGen): BuildRuleFile =3D None if TAB_TAT_DEFINES_BUILD_RULE_CONF in self.Workspace.TargetTxt= .TargetTxtDictionary: BuildRuleFile =3D self.Workspace.TargetTxt.TargetTxtDictio= nary[TAB_TAT_DEFINES_BUILD_RULE_CONF] - if BuildRuleFile in [None, '']: + if not BuildRuleFile: BuildRuleFile =3D gDefaultBuildRuleFile self._BuildRule =3D BuildRule(BuildRuleFile) if self._BuildRule._FileVersion =3D=3D "": @@ -2327,13 +2327,13 @@ class PlatformAutoGen(AutoGen): TokenCName =3D PcdItem[0] break if FromPcd is not None: - if ToPcd.Pending and FromPcd.Type not in [None, '']: + if ToPcd.Pending and FromPcd.Type: ToPcd.Type =3D FromPcd.Type - elif (ToPcd.Type not in [None, '']) and (FromPcd.Type not in [= None, ''])\ + elif (ToPcd.Type) and (FromPcd.Type)\ and (ToPcd.Type !=3D FromPcd.Type) and (ToPcd.Type in From= Pcd.Type): if ToPcd.Type.strip() =3D=3D TAB_PCDS_DYNAMIC_EX: ToPcd.Type =3D FromPcd.Type - elif ToPcd.Type not in [None, ''] and FromPcd.Type not in [Non= e, ''] \ + elif ToPcd.Type and FromPcd.Type \ and ToPcd.Type !=3D FromPcd.Type: EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD = type", ExtraData=3D"%s.%s is defined as [%s] in m= odule %s, but as [%s] in platform."\ @@ -2369,11 +2369,11 @@ class Platform= AutoGen(AutoGen): ToPcd.validlists =3D FromPcd.validlists ToPcd.expressions =3D FromPcd.expressions =20 - if FromPcd is not None and ToPcd.DatumType =3D=3D "VOID*" and ToPc= d.MaxDatumSize in ['', None]: + if FromPcd is not None and ToPcd.DatumType =3D=3D "VOID*" and not = ToPcd.MaxDatumSize: EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified = for PCD %s.%s" \ % (ToPcd.TokenSpaceGuidCName, TokenCName)) Value =3D ToPcd.DefaultValue - if Value in [None, '']: + if not Value: ToPcd.MaxDatumSize =3D '1' elif Value[0] =3D=3D 'L': ToPcd.MaxDatumSize =3D str((len(Value) - 2) * 2) @@ -2384,= 7 +2384,7 @@ class PlatformAutoGen(AutoGen): =20 # apply default SKU for dynamic PCDS if specified one is not avail= able if (ToPcd.Type in PCD_DYNAMIC_TYPE_SET or ToPcd.Type in PCD_DYNAMI= C_EX_TYPE_SET) \ - and ToPcd.SkuInfoList in [None, {}, '']: + and not ToPcd.SkuInfoList: if self.Platform.SkuName in self.Platform.SkuIds: SkuName =3D self.Platform.SkuName else: @@ -2445,10 +2445,10 @@ class PlatformAutoGen(AutoGen): # use PCD value to calculate the MaxDatumSize when it is not speci= fied for Name, Guid in Pcds: Pcd =3D Pcds[Name, Guid] - if Pcd.DatumType =3D=3D "VOID*" and Pcd.MaxDatumSize in ['', N= one]: + if Pcd.DatumType =3D=3D "VOID*" and not Pcd.MaxDatumSize: Pcd.MaxSizeUserSet =3D None Value =3D Pcd.DefaultValue - if Value in [None, '']: + if not Value: Pcd.MaxDatumSize =3D '1' elif Value[0] =3D=3D 'L': Pcd.MaxDatumSize =3D str((len(Value) - 2) * 2) diff --= git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Python/Aut= oGen/GenC.py index ca54ac107e5d..a020d5f5e58a 100644 --- a/BaseTools/Source/Python/AutoGen/GenC.py +++ b/BaseTools/Source/Python/AutoGen/GenC.py @@ -867,7 +867,7 @@ def DynExPcdTokenNumberMapping(Info, AutoGenH): def GetPcdSize(Pcd): if Pcd.DatumType not in _NumericDataTypesList: Value =3D Pcd.DefaultValue - if Value in [None, '']: + if not Value: return 1 elif Value[0] =3D=3D 'L': return (len(Value) - 2) * 2 diff --git a/BaseTools/Source/Pyth= on/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStateme= nt.py index b92fa4d8033c..a26097813bcc 100644 --- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py @@ -297,7 +297,7 @@ class FfsInfStatement(FfsInfStatementClassObject): =20 # Check value, if value are equal, no need to patch if Pcd.DatumType =3D=3D "VOID*": - if Pcd.InfDefaultValue =3D=3D DefaultValue or DefaultValue= in [None, '']: + if Pcd.InfDefaultValue =3D=3D DefaultValue or not DefaultV= alue: continue # Get the string size from FDF or DSC if DefaultValue[0] =3D=3D 'L': @@ -310,7 +310,7 @@ class FfsInfStatement(FfsInfStatementClassObject): if DscOverride: Pcd.MaxDatumSize =3D PatchPcd.MaxDatumSize # If no defined the maximum size in DSC, try to get curren= t size from INF - if Pcd.MaxDatumSize in ['', None]: + if not Pcd.MaxDatumSize: Pcd.MaxDatumSize =3D str(len(Pcd.InfDefaultValue.split= (','))) else: Base1 =3D Base2 =3D 10 diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py b/BaseT= ools/Source/Python/GenFds/GenFdsGlobalVariable.py index 878b13d13c2d..3a745dc4175e 100644 --- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py +++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py @@ -102,7 +102,7 @@ class GenFdsGlobalVariable: TargetTxt.LoadTargetTxtFile(BuildConfigurationFile) if DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF in TargetTxt.Targe= tTxtDictionary: BuildRuleFile =3D TargetTxt.TargetTxtDictionary[DataType.T= AB_TAT_DEFINES_BUILD_RULE_CONF] - if BuildRuleFile in [None, '']: + if not BuildRuleFile: BuildRuleFile =3D 'Conf/build_rule.txt' GenFdsGlobalVariable.__BuildRuleDatabase =3D BuildRule(BuildRu= leFile) ToolDefinitionFile =3D TargetTxt.TargetTxtDictionary[DataType.= TAB_TAT_DEFINES_TOOL_CHAIN_CONF] @@ -441,15 +441,15 @@ class GenFdsGlobalVariable: def GenerateSection(Output, Input, Type=3DNone, CompressionType=3DNone= , Guid=3DNone, GuidHdrLen=3DNone, GuidAttr=3D[], Ui=3DNone, Ver= =3DNone, InputAlign=3DNone, BuildNumber=3DNone, DummyFile=3DNone, IsMakefil= e=3DFalse): Cmd =3D ["GenSec"] - if Type not in [None, '']: + if Type: Cmd +=3D ["-s", Type] - if CompressionType not in [None, '']: + if CompressionType: Cmd +=3D ["-c", CompressionType] if Guid is not None: Cmd +=3D ["-g", Guid] if DummyFile is not None: Cmd +=3D ["--dummy", DummyFile] - if GuidHdrLen not in [None, '']: + if GuidHdrLen: Cmd +=3D ["-l", GuidHdrLen] if len(GuidAttr) !=3D 0: #Add each guided attribute @@ -461,7 +461,7 @@ class GenFdsGlobalVariable: Cmd +=3D ["--sectionalign", SecAlign] =20 CommandFile =3D Output + '.txt' - if Ui not in [None, '']: + if Ui: #Cmd +=3D ["-n", '"' + Ui + '"'] if IsMakefile: if Ui =3D=3D "$(MODULE_NAME)": @@ -480,7 +480,7 @@ class GenFdsGlobalVariable: GenFdsGlobalVariable.SectionHeader.pack_into(SectionData, = 0, Len & 0xff, (Len >> 8) & 0xff, (Len >> 16) & 0xff, 0x15) SaveFileOnChange(Output, SectionData.tostring()) =20 - elif Ver not in [None, '']: + elif Ver: Cmd +=3D ["-n", Ver] if BuildNumber: Cmd +=3D ["-j", BuildNumber] @@ -529,7 +529,7 @@ class Gen= FdsGlobalVariable: Cmd +=3D ["-x"] if CheckSum: Cmd +=3D ["-s"] - if Align not in [None, '']: + if Align: if Align not in mFfsValidAlign: Align =3D GenFdsGlobalVariable.GetAlignment (Align) for index in range(0, len(mFfsValidAlign) - 1): @@ -541,7 +541,7 @@ class GenFdsGlobalVariable: Cmd +=3D ["-o", Output] for I in range(0, len(Input)): Cmd +=3D ("-i", Input[I]) - if SectionAlign not in [None, '', []] and SectionAlign[I] not = in [None, '']: + if SectionAlign and SectionAlign[I]: Cmd +=3D ("-n", SectionAlign[I]) =20 CommandFile =3D Output + '.txt' @@ -566,7 +566,7 @@ class GenFdsGlobalVariable: GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs upda= te because of newer %s" % (Output, Input)) =20 Cmd =3D ["GenFv"] - if BaseAddress not in [None, '']: + if BaseAddress: Cmd +=3D ["-r", BaseAddress] =20 if ForceRebase =3D=3D False: @@ -578,9 +578,9 @@ class GenFdsGlobalVariable: Cmd +=3D ["-c"] if Dump: Cmd +=3D ["-p"] - if AddressFile not in [None, '']: + if AddressFile: Cmd +=3D ["-a", AddressFile] - if MapFile not in [None, '']: + if MapFile: Cmd +=3D ["-m", MapFile] if FileSystemGuid: Cmd +=3D ["-g", FileSystemGuid] @@ -597,7 +597,7 @@ class GenF= dsGlobalVariable: GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs upda= te because of newer %s" % (Output, Input)) =20 Cmd =3D ["GenVtf"] - if BaseAddress not in [None, ''] and FvSize not in [None, ''] \ + if BaseAddress and FvSize \ and len(BaseAddress) =3D=3D len(FvSize): for I in range(0, len(BaseAddress)): Cmd +=3D ["-r", BaseAddress[I], "-s", FvSize[I]] @@ -618,1= 3 +618,13 @@ class GenFdsGlobalVariable: Cmd =3D ["GenFw"] if Type.lower() =3D=3D "te": Cmd +=3D ["-t"] - if SubType not in [None, '']: + if SubType: Cmd +=3D ["-e", SubType] - if TimeStamp not in [None, '']: + if TimeStamp: Cmd +=3D ["-s", TimeStamp] - if Align not in [None, '']: + if Align: Cmd +=3D ["-a", Align] - if Padding not in [None, '']: + if Padding: Cmd +=3D ["-p", Padding] if Zero: Cmd +=3D ["-z"] diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/= Source/Python/Workspace/DscBuildData.py index 6943fab4e5c8..91a9928c00d2 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -641,10 +641,10 @@ class DscBuildData(PlatformBuildClassObject): self._SkuIds =3D OrderedDict() RecordList =3D self._RawData[MODEL_EFI_SKU_ID, self._Arch] for Record in RecordList: - if Record[0] in [None, '']: + if not Record[0]: EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID nu= mber', File=3Dself.MetaFile, Line=3DRecord[-1= ]) - if Record[1] in [None, '']: + if not Record[1]: EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID na= me', File=3Dself.MetaFile, Line=3DRecord[-1= ]) if not Pattern.match(Record[0]) and not HexPattern.match(R= ecord[0]): @@ -669,10 +669,10 @@ class DscBuildData(PlatformBuildClassObject): self.DefaultStores =3D OrderedDict() RecordList =3D self._RawData[MODEL_EFI_DEFAULT_STORES, self._A= rch] for Record in RecordList: - if Record[0] in [None, '']: + if not Record[0]: EdkLogger.error('build', FORMAT_INVALID, 'No DefaultSt= ores ID number', File=3Dself.MetaFile, Line=3DRecord[-1= ]) - if Record[1] in [None, '']: + if not Record[1]: EdkLogger.error('build', FORMAT_INVALID, 'No DefaultSt= ores ID name', File=3Dself.MetaFile, Line=3DRecord[-1= ]) if not Pattern.match(Record[0]) and not HexPattern.match(R= ecord[0]): diff --git a/BaseTools/Source/Python/Workspace/InfBuildData.py b/BaseTools/= Source/Python/Workspace/InfBuildData.py index cf5e1df3a523..602746de32f7 100644 --- a/BaseTools/Source/Python/Workspace/InfBuildData.py +++ b/BaseTools/Source/Python/Workspace/InfBuildData.py @@ -1116,7 +1116,7 @@ class InfBuildData(ModuleBuildClassObject): Pcd.DatumType =3D PcdInPackage.DatumType Pcd.MaxDatumSize =3D PcdInPackage.MaxDatumSize Pcd.InfDefaultValue =3D Pcd.DefaultValue - if Pcd.DefaultValue in [None, '']: + if not Pcd.DefaultValue: Pcd.DefaultValue =3D PcdInPackage.DefaultValue else: try: -- 2.16.2.windows.1