BaseTools: use single RegExp for token matching
authorCarsey, Jaben </o=Intel/ou=Americas01/cn=Workers/cn=Carsey, Jaben>
Thu, 29 Mar 2018 21:38:06 +0000 (05:38 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Tue, 3 Apr 2018 09:35:31 +0000 (17:35 +0800)
same pattern was compiled 3 places in the file.  just compile once and share.

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

index 66815d3e17fe53125ab93b5e418ec425ac1a33b5..255ca9633aa180abe4fd2603bc23ebee109fe08e 100644 (file)
@@ -49,6 +49,7 @@ InputMacroDict = {}
 AllMacroList = []\r
 \r
 FileExtensionPattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)')\r
+TokenFindPattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')\r
 \r
 def GetRealFileLine (File, Line):\r
     \r
@@ -2094,8 +2095,7 @@ class FdfParser(object):
 \r
                 \r
         if self.__GetNextToken():\r
-            p = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')\r
-            if p.match(self.__Token):\r
+            if TokenFindPattern.match(self.__Token):\r
                 FfsInfObj.KeyStringList.append(self.__Token)\r
                 if not self.__IsToken(","):\r
                     return\r
@@ -2104,7 +2104,7 @@ class FdfParser(object):
                 return\r
                 \r
             while self.__GetNextToken():\r
-                if not p.match(self.__Token):\r
+                if not TokenFindPattern.match(self.__Token):\r
                     raise Warning("expected KeyString \"Target_Tag_Arch\" At Line ", self.FileName, self.CurrentLineNumber)\r
                 FfsInfObj.KeyStringList.append(self.__Token)\r
     \r
@@ -2252,12 +2252,11 @@ class FdfParser(object):
     def __GetFileOpts(self, FfsFileObj):\r
         \r
         if self.__GetNextToken():\r
-            Pattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')\r
-            if Pattern.match(self.__Token):\r
+            if TokenFindPattern.match(self.__Token):\r
                 FfsFileObj.KeyStringList.append(self.__Token)\r
                 if self.__IsToken(","):\r
                     while self.__GetNextToken():\r
-                        if not Pattern.match(self.__Token):\r
+                        if not TokenFindPattern.match(self.__Token):\r
                             raise Warning("expected KeyString \"Target_Tag_Arch\" At Line ", self.FileName, self.CurrentLineNumber)\r
                         FfsFileObj.KeyStringList.append(self.__Token)\r
 \r
@@ -2902,12 +2901,11 @@ class FdfParser(object):
         \r
         KeyStringList = []\r
         if self.__GetNextToken():\r
-            Pattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')\r
-            if Pattern.match(self.__Token):\r
+            if TokenFindPattern.match(self.__Token):\r
                 KeyStringList.append(self.__Token)\r
                 if self.__IsToken(","):\r
                     while self.__GetNextToken():\r
-                        if not Pattern.match(self.__Token):\r
+                        if not TokenFindPattern.match(self.__Token):\r
                             raise Warning("expected KeyString \"Target_Tag_Arch\" At Line ", self.FileName, self.CurrentLineNumber)\r
                         KeyStringList.append(self.__Token)\r
 \r