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>
This commit is contained in:
Carsey, Jaben 2018-03-27 08:33:08 +08:00 committed by Yonghong Zhu
parent e52aed0d85
commit cc0321f22a
1 changed files with 5 additions and 4 deletions

View File

@ -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 = []