BaseTools: GenFds - move RegEx compile
authorCarsey, Jaben </o=Intel/ou=Americas01/cn=Workers/cn=Carsey, Jaben>
Tue, 3 Apr 2018 22:34:03 +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/GenFds/FdfParser.py

index 9b7e898570a3ecfd0d34364fa1ba65b4f519bd59..00e03446421d1953725f9f5c6dc0f2cad2cf03c5 100644 (file)
@@ -85,6 +85,7 @@ RegionSizePattern = re.compile("\s*(?P<base>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<s
 RegionSizeGuidPattern = re.compile("\s*(?P<base>\w+\.\w+)\s*\|\s*(?P<size>\w+\.\w+)\s*")\r
 RegionOffsetPcdPattern = re.compile("\s*(?P<base>\w+\.\w+)\s*$")\r
 ShortcutPcdPattern = re.compile("\s*\w+\s*=\s*(?P<value>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<name>\w+\.\w+)\s*")\r
 RegionSizeGuidPattern = re.compile("\s*(?P<base>\w+\.\w+)\s*\|\s*(?P<size>\w+\.\w+)\s*")\r
 RegionOffsetPcdPattern = re.compile("\s*(?P<base>\w+\.\w+)\s*$")\r
 ShortcutPcdPattern = re.compile("\s*\w+\s*=\s*(?P<value>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<name>\w+\.\w+)\s*")\r
+BaseAddrValuePattern = re.compile('^0[xX][0-9a-fA-F]+')\r
 \r
 AllIncludeFileList = []\r
 \r
 \r
 AllIncludeFileList = []\r
 \r
@@ -2211,9 +2212,7 @@ class FdfParser:
         if not self.__GetNextToken():\r
             raise Warning("expected FV base address value", self.FileName, self.CurrentLineNumber)\r
 \r
         if not self.__GetNextToken():\r
             raise Warning("expected FV base address value", self.FileName, self.CurrentLineNumber)\r
 \r
-        IsValidBaseAddrValue = re.compile('^0[x|X][0-9a-fA-F]+')\r
-\r
-        if not IsValidBaseAddrValue.match(self.__Token.upper()):\r
+        if not BaseAddrValuePattern.match(self.__Token.upper()):\r
             raise Warning("Unknown FV base address value '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
         Obj.FvBaseAddress = self.__Token\r
         return True  \r
             raise Warning("Unknown FV base address value '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
         Obj.FvBaseAddress = self.__Token\r
         return True  \r