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 v1 08/11] BaseTools: refactor to change object types
Date: Wed, 20 Jun 2018 14:08:14 -0700 [thread overview]
Message-ID: <3e85c992530cabe164c0d2e7c84c27a0c6fb7b0c.1529528784.git.jaben.carsey@intel.com> (raw)
In-Reply-To: <cover.1529528783.git.jaben.carsey@intel.com>
In-Reply-To: <cover.1529528783.git.jaben.carsey@intel.com>
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 <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/AutoGen/AutoGen.py | 8 ++++++--
BaseTools/Source/Python/GenFds/FdfParser.py | 5 +++--
BaseTools/Source/Python/Workspace/WorkspaceCommon.py | 20 ++++++++++----------
3 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index 4ce39cf9583a..c4c415f8ef57 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -48,11 +48,15 @@ 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 Workspace.WorkspaceCommon import OrderedListDict
from abc import ABCMeta, abstractmethod
+class OrderedListDict(OrderedDict, defaultdict):
+ def __init__(self, *args, **kwargs):
+ super(OrderedListDict, self).__init__(*args, **kwargs)
+ self.default_factory = list
+
## Regular expression for splitting Dependency Expression string into tokens
gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index af1760bf729c..f1472b8d6be2 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
from GenFdsGlobalVariable import GenFdsGlobalVariable
from Common.BuildToolError import *
@@ -89,7 +90,7 @@ BaseAddrValuePattern = re.compile('^0[xX][0-9a-fA-F]+')
FileExtensionPattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)')
TokenFindPattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')
-AllIncludeFileList = []
+AllIncludeFileList = deque()
# Get the closest parent
def GetParentAtLine (Line):
@@ -685,7 +686,7 @@ class FdfParser:
InsertAtLine += 1
# reversely sorted to better determine error in file
- AllIncludeFileList.insert(0, IncFileProfile)
+ AllIncludeFileList.appendleft(IncFileProfile)
# comment out the processed include file statement
TempList = list(self.Profile.FileLinesList[IncludeLine - 1])
diff --git a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py
index 713c1ddbddc9..a3fb1ee3fca4 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 IMPLIED.
#
-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 GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
# EdkII module
LibraryConsumerList = [Module]
- Constructor = []
+ Constructor = set()
ConsumedByList = OrderedListDict()
LibraryInstance = OrderedDict()
@@ -166,7 +166,7 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
continue
if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:
- Constructor.append(LibraryModule)
+ Constructor.add(LibraryModule)
# don't add current module itself to consumer list
if M != Module:
@@ -180,8 +180,8 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
#
# Q <- Set of all nodes with no incoming edges
#
- LibraryList = [] #LibraryInstance.values()
- Q = []
+ LibraryList = []
+ Q = deque()
for LibraryClassName in LibraryInstance:
M = LibraryInstance[LibraryClassName]
LibraryList.append(M)
@@ -193,7 +193,7 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
#
while True:
EdgeRemoved = True
- while Q == [] and EdgeRemoved:
+ while not Q and EdgeRemoved:
EdgeRemoved = False
# for each node Item with a Constructor
for Item in LibraryList:
@@ -208,12 +208,12 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
EdgeRemoved = True
if not ConsumedByList[Item]:
# insert Item into Q
- Q.insert(0, Item)
+ Q.appendleft(Item)
break
- if Q != []:
+ if Q:
break
# DAG is done if there's no more incoming edge for all nodes
- if Q == []:
+ if not Q:
break
# remove node from Q
@@ -231,7 +231,7 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
if ConsumedByList[Item]:
continue
# insert Item into Q, if Item has no other incoming edges
- Q.insert(0, Item)
+ Q.appendleft(Item)
#
# if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle
--
2.16.2.windows.1
next prev parent reply other threads:[~2018-06-20 21:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-20 21:08 [PATCH v2 00/11] BaseTools Refactoring Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 01/11] BaseTools: decorate base classes to prevent instantiation Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 02/11] BaseTools: Workspace - create a base class Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 03/11] BaseTools: remove unused code Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 04/11] BaseTools: remove repeated calls to startswith/endswith Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 05/11] BaseTools: use set presence instead of series of equality Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 06/11] BaseTools: refactor section generation Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 07/11] BaseTools: refactor file opening/writing Jaben Carsey
2018-06-20 21:08 ` Jaben Carsey [this message]
2018-06-20 21:08 ` [PATCH v1 09/11] BaseTools: refactor to stop re-allocating strings Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 10/11] BaseTools: change to set for membership testing Jaben Carsey
2018-06-20 21:08 ` [PATCH v1 11/11] BaseTools: remove extra assignment Jaben Carsey
-- strict thread matches above, loose matches on Subject: below --
2018-05-14 18:09 [PATCH v1 00/11] BaseTools refactoring Jaben Carsey
2018-05-14 18:09 ` [PATCH v1 08/11] BaseTools: refactor to change object types Jaben Carsey
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=3e85c992530cabe164c0d2e7c84c27a0c6fb7b0c.1529528784.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