BaseTools: Autogen - move RegEx compile
authorCarsey, Jaben </o=Intel/ou=Americas01/cn=Workers/cn=Carsey, Jaben>
Tue, 3 Apr 2018 22:34:02 +0000 (06:34 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Sun, 8 Apr 2018 07:34:10 +0000 (15:34 +0800)
compile each RegEx once not in loops/functions

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/AutoGen/AutoGen.py

index 3865827f26df751814d3eda57f2636641b7ec082..4088fb9c8b7d641846e47600f603b0dcff6fa86f 100644 (file)
@@ -50,6 +50,16 @@ from collections import OrderedDict
 ## Regular expression for splitting Dependency Expression string into tokens\r
 gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")\r
 \r
+## Regular expression for match: PCD(xxxx.yyy)\r
+gPCDAsGuidPattern = re.compile(r"^PCD\(.+\..+\)$")\r
+\r
+#\r
+# Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT\r
+# is the former use /I , the Latter used -I to specify include directories\r
+#\r
+gBuildOptIncludePatternMsft = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
+gBuildOptIncludePatternOther = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
+\r
 #\r
 # Match name = variable\r
 #\r
@@ -819,13 +829,11 @@ class WorkspaceAutoGen(AutoGen):
                         InfFoundFlag = False\r
 \r
                 if FfsFile.NameGuid is not None:\r
-                    _CheckPCDAsGuidPattern = re.compile("^PCD\(.+\..+\)$")\r
-\r
                     #\r
                     # If the NameGuid reference a PCD name. \r
                     # The style must match: PCD(xxxx.yyy)\r
                     #\r
-                    if _CheckPCDAsGuidPattern.match(FfsFile.NameGuid):\r
+                    if gPCDAsGuidPattern.match(FfsFile.NameGuid):\r
                         #\r
                         # Replace the PCD value.\r
                         #\r
@@ -3316,9 +3324,9 @@ class ModuleAutoGen(AutoGen):
             # is the former use /I , the Latter used -I to specify include directories\r
             #\r
             if self.PlatformInfo.ToolChainFamily in ('MSFT'):\r
-                gBuildOptIncludePattern = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
+                BuildOptIncludeRegEx = gBuildOptIncludePatternMsft\r
             elif self.PlatformInfo.ToolChainFamily in ('INTEL', 'GCC', 'RVCT'):\r
-                gBuildOptIncludePattern = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
+                BuildOptIncludeRegEx = gBuildOptIncludePatternOther\r
             else:\r
                 #\r
                 # New ToolChainFamily, don't known whether there is option to specify include directories\r
@@ -3335,13 +3343,13 @@ class ModuleAutoGen(AutoGen):
                     FlagOption = ''\r
                 \r
                 if self.PlatformInfo.ToolChainFamily != 'RVCT':\r
-                    IncPathList = [NormPath(Path, self.Macros) for Path in gBuildOptIncludePattern.findall(FlagOption)]\r
+                    IncPathList = [NormPath(Path, self.Macros) for Path in BuildOptIncludeRegEx.findall(FlagOption)]\r
                 else:\r
                     #\r
                     # RVCT may specify a list of directory seperated by commas\r
                     #\r
                     IncPathList = []\r
-                    for Path in gBuildOptIncludePattern.findall(FlagOption):\r
+                    for Path in BuildOptIncludeRegEx.findall(FlagOption):\r
                         PathList = GetSplitList(Path, TAB_COMMA_SPLIT)\r
                         IncPathList += [NormPath(PathEntry, self.Macros) for PathEntry in PathList]\r
 \r