summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/Common/Misc.py
diff options
context:
space:
mode:
authorBobCF <bob.c.feng@intel.com>2018-11-08 18:16:25 +0800
committerBobCF <bob.c.feng@intel.com>2018-12-07 10:30:21 +0800
commit4e375707392e4f9085e2d2342e41aee9d4df2b0a (patch)
tree35f6608ddc57cb9a46ddd5f4496b6c8bdfb1bdf3 /BaseTools/Source/Python/Common/Misc.py
parent2f818ed0fb57d98985d151781a2ce9b8683129ee (diff)
downloadedk2-4e375707392e4f9085e2d2342e41aee9d4df2b0a.tar.gz
edk2-4e375707392e4f9085e2d2342e41aee9d4df2b0a.tar.bz2
edk2-4e375707392e4f9085e2d2342e41aee9d4df2b0a.zip
BaseTools: Optimize string concatenation
https://bugzilla.tianocore.org/show_bug.cgi?id=1288 This patch is one of build tool performance improvement series patches. This patch is going to use join function instead of string += string2 statement. Current code use string += string2 in a loop to combine a string. while creating a string list in a loop and using "".join(stringlist) after the loop will be much faster. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: BobCF <bob.c.feng@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/Common/Misc.py')
-rw-r--r--BaseTools/Source/Python/Common/Misc.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index 2354f392f2..84f3f16ee6 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -778,7 +778,7 @@ class TemplateString(object):
## Constructor
def __init__(self, Template=None):
- self.String = ''
+ self.String = []
self.IsBinary = False
self._Template = Template
self._TemplateSectionList = self._Parse(Template)
@@ -788,7 +788,7 @@ class TemplateString(object):
# @retval string The string replaced
#
def __str__(self):
- return self.String
+ return "".join(self.String)
## Split the template string into fragments per the ${BEGIN} and ${END} flags
#
@@ -836,9 +836,12 @@ class TemplateString(object):
def Append(self, AppendString, Dictionary=None):
if Dictionary:
SectionList = self._Parse(AppendString)
- self.String += "".join(S.Instantiate(Dictionary) for S in SectionList)
+ self.String.append( "".join(S.Instantiate(Dictionary) for S in SectionList))
else:
- self.String += AppendString
+ if isinstance(AppendString,list):
+ self.String.extend(AppendString)
+ else:
+ self.String.append(AppendString)
## Replace the string template with dictionary of placeholders
#
@@ -1744,10 +1747,7 @@ class PathClass(object):
# @retval True The two PathClass are the same
#
def __eq__(self, Other):
- if isinstance(Other, type(self)):
- return self.Path == Other.Path
- else:
- return self.Path == str(Other)
+ return self.Path == str(Other)
## Override __cmp__ function
#
@@ -1757,10 +1757,7 @@ class PathClass(object):
# @retval -1 The first PathClass is less than the second PathClass
# @retval 1 The first PathClass is Bigger than the second PathClass
def __cmp__(self, Other):
- if isinstance(Other, type(self)):
- OtherKey = Other.Path
- else:
- OtherKey = str(Other)
+ OtherKey = str(Other)
SelfKey = self.Path
if SelfKey == OtherKey: