diff options
author | BobCF <bob.c.feng@intel.com> | 2018-11-08 14:03:38 +0800 |
---|---|---|
committer | BobCF <bob.c.feng@intel.com> | 2018-12-07 10:31:04 +0800 |
commit | bf9e636605188e291d33ab694ff1c5926b6f0800 (patch) | |
tree | ed9c6534d4cda516d290f979ba2848a882928508 /BaseTools/Source/Python/Common | |
parent | 4e375707392e4f9085e2d2342e41aee9d4df2b0a (diff) | |
download | edk2-bf9e636605188e291d33ab694ff1c5926b6f0800.tar.gz edk2-bf9e636605188e291d33ab694ff1c5926b6f0800.tar.bz2 edk2-bf9e636605188e291d33ab694ff1c5926b6f0800.zip |
BaseTools: Customize deepcopy function.
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 customize the deepcopy function for
SkuClass, PcdClassObject and python dictionary.
python deepcopy copy everything of a object, but for our current
usage we just need to copy the data we care about recursively.
By implementing __deepcopy__ for SkuClass, PcdClassObject, we can customize
deepcopy function for them.
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: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/Common')
-rw-r--r-- | BaseTools/Source/Python/Common/Expression.py | 4 | ||||
-rw-r--r-- | BaseTools/Source/Python/Common/Misc.py | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py index a5f085d7fb..19ea13b7fb 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -17,7 +17,7 @@ from __future__ import absolute_import from Common.GlobalData import *
from CommonDataClass.Exceptions import BadExpression
from CommonDataClass.Exceptions import WrnExpression
-from .Misc import GuidStringToGuidStructureString, ParseFieldValue
+from .Misc import GuidStringToGuidStructureString, ParseFieldValue,CopyDict
import Common.EdkLogger as EdkLogger
import copy
from Common.DataType import *
@@ -355,7 +355,7 @@ class ValueExpression(BaseExpression): #
# The symbol table including PCD and macro mapping
#
- self._Symb = copy.deepcopy(SymbolTable)
+ self._Symb = CopyDict(SymbolTable)
self._Symb.update(self.LogicalOperators)
self._Idx = 0
self._Len = len(self._Expr)
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py index 84f3f16ee6..b063f064fb 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -41,6 +41,7 @@ import uuid from CommonDataClass.Exceptions import BadExpression
from Common.caching import cached_property
import subprocess
+from collections import OrderedDict
## Regular expression used to find out place holders in string template
gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)
@@ -2130,6 +2131,21 @@ def PackByteFormatGUID(Guid): Guid[10],
)
+## DeepCopy dict/OrderedDict recusively
+#
+# @param ori_dict a nested dict or ordereddict
+#
+# @retval new dict or orderdict
+#
+def CopyDict(ori_dict):
+ dict_type = ori_dict.__class__
+ new_dict = dict_type()
+ for key in ori_dict:
+ if isinstance(ori_dict[key],(dict,OrderedDict)):
+ new_dict[key] = CopyDict(ori_dict[key])
+ else:
+ new_dict[key] = ori_dict[key]
+ return new_dict
##
#
# This acts like the main() function for the script, unless it is 'import'ed into another
|