diff options
author | Carsey, Jaben </o=Intel/ou=Americas01/cn=Workers/cn=Carsey, Jaben> | 2018-03-27 08:33:08 +0800 |
---|---|---|
committer | Yonghong Zhu <yonghong.zhu@intel.com> | 2018-03-29 16:33:55 +0800 |
commit | cc0321f22ac7422a2d477c98fed209547eaf0cb5 (patch) | |
tree | 5368cd09643879d78d111ae14660fc25d976dd3b /BaseTools/Source/Python/Common | |
parent | e52aed0d855218f23cbd94629561eb4155936cec (diff) | |
download | edk2-cc0321f22ac7422a2d477c98fed209547eaf0cb5.tar.gz edk2-cc0321f22ac7422a2d477c98fed209547eaf0cb5.tar.bz2 edk2-cc0321f22ac7422a2d477c98fed209547eaf0cb5.zip |
BaseTools: refactor repeated RegExp when no special searching is needed.
use str.replace and try/except.
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>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/Common')
-rw-r--r-- | BaseTools/Source/Python/Common/Expression.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py index 09240de697..9a844b0417 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -936,12 +936,13 @@ class ValueExpressionEx(ValueExpression): OffsetList = _ReOffset.findall(Item)
except:
pass
+ # replace each offset, except errors
for Offset in OffsetList:
- if Offset in LabelDict.keys():
- Re = re.compile('OFFSET_OF\(%s\)' % Offset)
- Item = Re.sub(LabelDict[Offset], Item)
- else:
+ try:
+ Item = Item.replace('OFFSET_OF({})'.format(Offset),LabelDict[Offset])
+ except:
raise BadExpression('%s not defined' % Offset)
+
NewPcdValueList.append(Item)
AllPcdValueList = []
|