From cc0321f22ac7422a2d477c98fed209547eaf0cb5 Mon Sep 17 00:00:00 2001 From: "Carsey, Jaben" Date: Tue, 27 Mar 2018 08:33:08 +0800 Subject: [PATCH] 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 --- BaseTools/Source/Python/Common/Expression.py | 9 +++++---- 1 file 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 = []