From: Carsey, Jaben Date: Tue, 27 Mar 2018 00:33:08 +0000 (+0800) Subject: BaseTools: refactor repeated RegExp when no special searching is needed. X-Git-Tag: edk2-stable201903~2015 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=cc0321f22ac7422a2d477c98fed209547eaf0cb5;ds=sidebyside BaseTools: refactor repeated RegExp when no special searching is needed. use str.replace and try/except. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey Reviewed-by: Yonghong Zhu --- 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 = []