BaseTools: move regular expression compile out of function call.
[mirror_edk2.git] / 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