From: Carsey, Jaben Date: Tue, 27 Mar 2018 23:42:46 +0000 (+0800) Subject: BaseTools: move regular expression compile out of function call. X-Git-Tag: edk2-stable201903~2017 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=38504ad3e3163fd8afbfc66760455df9dd223713;hp=663b9e061ed1b48e562159e51333e996f1efc830 BaseTools: move regular expression compile out of function call. move to the root of the file and dont recompile. 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 30711cedd7..4a7cd974b1 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -41,6 +41,8 @@ ERR_EMPTY_EXPR = 'Empty expression is not allowed.' ERR_IN_OPERAND = 'Macro after IN operator can only be: $(FAMILY), $(ARCH), $(TOOL_CHAIN_TAG) and $(TARGET).' __ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$') +_ReLabel = re.compile('LABEL\((\w+)\)') +_ReOffset = re.compile('OFFSET_OF\((\w+)\)') ## SplitString # Split string to list according double quote @@ -896,13 +898,11 @@ class ValueExpressionEx(ValueExpression): PcdValueList = SplitPcdValueString(PcdValue.strip()[1:-1]) LabelDict = {} NewPcdValueList = [] - ReLabel = re.compile('LABEL\((\w+)\)') - ReOffset = re.compile('OFFSET_OF\((\w+)\)') LabelOffset = 0 for Index, Item in enumerate(PcdValueList): # compute byte offset of every LABEL - LabelList = ReLabel.findall(Item) - Item = ReLabel.sub('', Item) + LabelList = _ReLabel.findall(Item) + Item = _ReLabel.sub('', Item) Item = Item.strip() if LabelList: for Label in LabelList: @@ -929,11 +929,11 @@ class ValueExpressionEx(ValueExpression): # for LABEL parse Item = Item.strip() try: - Item = ReLabel.sub('', Item) + Item = _ReLabel.sub('', Item) except: pass try: - OffsetList = ReOffset.findall(Item) + OffsetList = _ReOffset.findall(Item) except: pass for Offset in OffsetList: