BaseTools: move regular expression compile out of function call.
authorCarsey, Jaben </o=Intel/ou=Americas01/cn=Workers/cn=Carsey, Jaben>
Tue, 27 Mar 2018 23:42:46 +0000 (07:42 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Thu, 29 Mar 2018 08:28:43 +0000 (16:28 +0800)
move to the root of the file and dont recompile.

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>
BaseTools/Source/Python/Common/Expression.py

index 30711cedd784f83922430c39b95a7343f09a0473..4a7cd974b1212449a135e21ba0c34b5367476e9b 100644 (file)
@@ -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).'\r
 \r
 __ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')\r
+_ReLabel = re.compile('LABEL\((\w+)\)')\r
+_ReOffset = re.compile('OFFSET_OF\((\w+)\)')\r
 \r
 ## SplitString\r
 #  Split string to list according double quote\r
@@ -896,13 +898,11 @@ class ValueExpressionEx(ValueExpression):
                         PcdValueList = SplitPcdValueString(PcdValue.strip()[1:-1])\r
                         LabelDict = {}\r
                         NewPcdValueList = []\r
-                        ReLabel = re.compile('LABEL\((\w+)\)')\r
-                        ReOffset = re.compile('OFFSET_OF\((\w+)\)')\r
                         LabelOffset = 0\r
                         for Index, Item in enumerate(PcdValueList):\r
                             # compute byte offset of every LABEL\r
-                            LabelList = ReLabel.findall(Item)\r
-                            Item = ReLabel.sub('', Item)\r
+                            LabelList = _ReLabel.findall(Item)\r
+                            Item = _ReLabel.sub('', Item)\r
                             Item = Item.strip()\r
                             if LabelList:\r
                                 for Label in LabelList:\r
@@ -929,11 +929,11 @@ class ValueExpressionEx(ValueExpression):
                             # for LABEL parse\r
                             Item = Item.strip()\r
                             try:\r
-                                Item = ReLabel.sub('', Item)\r
+                                Item = _ReLabel.sub('', Item)\r
                             except:\r
                                 pass\r
                             try:\r
-                                OffsetList = ReOffset.findall(Item)\r
+                                OffsetList = _ReOffset.findall(Item)\r
                             except:\r
                                 pass\r
                             for Offset in OffsetList:\r