From nobody Sun Sep 7 12:22:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1526321396419822.0376744980775; Mon, 14 May 2018 11:09:56 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A4C562096AECE; Mon, 14 May 2018 11:09:27 -0700 (PDT) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 4C20021CAD9BA for ; Mon, 14 May 2018 11:09:25 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 May 2018 11:09:24 -0700 Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga001.jf.intel.com with ESMTP; 14 May 2018 11:09:24 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,401,1520924400"; d="scan'208";a="55814278" From: Jaben Carsey To: edk2-devel@lists.01.org Date: Mon, 14 May 2018 11:09:17 -0700 Message-Id: <271980cc1367f9a32c28b0ceb6cd7d040535ea9c.1526321053.git.jaben.carsey@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: In-Reply-To: References: Subject: [edk2] [PATCH v1 08/11] BaseTools: refactor to change object types 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: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" change to object types that are closer to use case. for example: when using a list as a double ended queue, use the built in object. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/AutoGen/AutoGen.py | 30 +++++++++++-----= ---- BaseTools/Source/Python/GenFds/FdfParser.py | 5 ++-- BaseTools/Source/Python/Workspace/WorkspaceCommon.py | 20 ++++++------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/= Python/AutoGen/AutoGen.py index 009e5c56781d..599331060187 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -45,10 +45,14 @@ import InfSectionParser import datetime import hashlib from GenVar import VariableMgr,var_info -from collections import OrderedDict -from collections import defaultdict +from collections import OrderedDict,defaultdict,deque from abc import ABCMeta, abstractmethod =20 +class OrderedListDict(OrderedDict, defaultdict): + def __init__(self, *args, **kwargs): + super(OrderedListDict, self).__init__(*args, **kwargs) + self.default_factory =3D list + ## Regular expression for splitting Dependency Expression string into toke= ns gDepexTokenPattern =3D re.compile("(\(|\)|\w+| \S+\.inf)") =20 @@ -2172,8 +2176,8 @@ class PlatformAutoGen(AutoGen): =20 # EdkII module LibraryConsumerList =3D [Module] - Constructor =3D [] - ConsumedByList =3D OrderedDict() + Constructor =3D set() + ConsumedByList =3D OrderedListDict() LibraryInstance =3D OrderedDict() =20 EdkLogger.verbose("") @@ -2219,10 +2223,8 @@ class PlatformAutoGen(AutoGen): continue =20 if LibraryModule.ConstructorList !=3D [] and LibraryModule= not in Constructor: - Constructor.append(LibraryModule) + Constructor.add(LibraryModule) =20 - if LibraryModule not in ConsumedByList: - ConsumedByList[LibraryModule] =3D [] # don't add current module itself to consumer list if M !=3D Module: if M in ConsumedByList[LibraryModule]: @@ -2235,8 +2237,8 @@ class PlatformAutoGen(AutoGen): # # Q <- Set of all nodes with no incoming edges # - LibraryList =3D [] #LibraryInstance.values() - Q =3D [] + LibraryList =3D [] + Q =3D deque() for LibraryClassName in LibraryInstance: M =3D LibraryInstance[LibraryClassName] LibraryList.append(M) @@ -2248,7 +2250,7 @@ class PlatformAutoGen(AutoGen): # while True: EdgeRemoved =3D True - while Q =3D=3D [] and EdgeRemoved: + while not Q and EdgeRemoved: EdgeRemoved =3D False # for each node Item with a Constructor for Item in LibraryList: @@ -2263,12 +2265,12 @@ class PlatformAutoGen(AutoGen): EdgeRemoved =3D True if ConsumedByList[Item] =3D=3D []: # insert Item into Q - Q.insert(0, Item) + Q.appendleft(Item) break - if Q !=3D []: + if Q: break # DAG is done if there's no more incoming edge for all nodes - if Q =3D=3D []: + if not Q: break =20 # remove node from Q @@ -2286,7 +2288,7 @@ class PlatformAutoGen(AutoGen): if ConsumedByList[Item] !=3D []: continue # insert Item into Q, if Item has no other incoming edges - Q.insert(0, Item) + Q.appendleft(Item) =20 # # if any remaining node Item in the graph has a constructor and an= incoming edge, then the graph has a cycle diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source= /Python/GenFds/FdfParser.py index 8d1a4b543f0e..d511cf4f9d5a 100644 --- a/BaseTools/Source/Python/GenFds/FdfParser.py +++ b/BaseTools/Source/Python/GenFds/FdfParser.py @@ -43,6 +43,7 @@ import OptionRom import OptRomInfStatement import OptRomFileStatement import string +from collections import deque =20 from GenFdsGlobalVariable import GenFdsGlobalVariable from Common.BuildToolError import * @@ -89,7 +90,7 @@ BaseAddrValuePattern =3D re.compile('^0[xX][0-9a-fA-F]+') FileExtensionPattern =3D re.compile(r'([a-zA-Z][a-zA-Z0-9]*)') TokenFindPattern =3D re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-= Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)') =20 -AllIncludeFileList =3D [] +AllIncludeFileList =3D deque() =20 # Get the closest parent def GetParentAtLine (Line): @@ -685,7 +686,7 @@ class FdfParser: InsertAtLine +=3D 1 =20 # reversely sorted to better determine error in file - AllIncludeFileList.insert(0, IncFileProfile) + AllIncludeFileList.appendleft(IncFileProfile) =20 # comment out the processed include file statement TempList =3D list(self.Profile.FileLinesList[IncludeLine -= 1]) diff --git a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py b/BaseToo= ls/Source/Python/Workspace/WorkspaceCommon.py index 573100081815..a793055b6d18 100644 --- a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py +++ b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. # =20 -from collections import OrderedDict, defaultdict +from collections import OrderedDict, defaultdict, deque from Common.DataType import SUP_MODULE_USER_DEFINED from BuildClassObject import LibraryClassObject import Common.GlobalData as GlobalData @@ -110,7 +110,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildD= atabase, Arch, Target, To =20 # EdkII module LibraryConsumerList =3D [Module] - Constructor =3D [] + Constructor =3D set() ConsumedByList =3D OrderedListDict() LibraryInstance =3D OrderedDict() =20 @@ -148,7 +148,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildD= atabase, Arch, Target, To continue =20 if LibraryModule.ConstructorList !=3D [] and LibraryModule not= in Constructor: - Constructor.append(LibraryModule) + Constructor.add(LibraryModule) =20 # don't add current module itself to consumer list if M !=3D Module: @@ -162,8 +162,8 @@ def _GetModuleLibraryInstances(Module, Platform, BuildD= atabase, Arch, Target, To # # Q <- Set of all nodes with no incoming edges # - LibraryList =3D [] #LibraryInstance.values() - Q =3D [] + LibraryList =3D [] + Q =3D deque() for LibraryClassName in LibraryInstance: M =3D LibraryInstance[LibraryClassName] LibraryList.append(M) @@ -175,7 +175,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildD= atabase, Arch, Target, To # while True: EdgeRemoved =3D True - while Q =3D=3D [] and EdgeRemoved: + while not Q and EdgeRemoved: EdgeRemoved =3D False # for each node Item with a Constructor for Item in LibraryList: @@ -190,12 +190,12 @@ def _GetModuleLibraryInstances(Module, Platform, Buil= dDatabase, Arch, Target, To EdgeRemoved =3D True if len(ConsumedByList[Item]) =3D=3D 0: # insert Item into Q - Q.insert(0, Item) + Q.appendleft(Item) break - if Q !=3D []: + if Q: break # DAG is done if there's no more incoming edge for all nodes - if Q =3D=3D []: + if not Q: break =20 # remove node from Q @@ -213,7 +213,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildD= atabase, Arch, Target, To if len(ConsumedByList[Item]) !=3D 0: continue # insert Item into Q, if Item has no other incoming edges - Q.insert(0, Item) + Q.appendleft(Item) =20 # # if any remaining node Item in the graph has a constructor and an inc= oming edge, then the graph has a cycle --=20 2.16.2.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel