BaseTools: FdfParser and FdfParserLite share reg exp
authorCarsey, Jaben </o=Intel/ou=Americas01/cn=Workers/cn=Carsey, Jaben>
Wed, 28 Mar 2018 16:04:57 +0000 (00:04 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Thu, 29 Mar 2018 00:34:09 +0000 (08:34 +0800)
FdfParser can share regular expression from FdfParserLite.
reduce overlap and reduce recompile of the same expression.
v2: fix missed replacement of Pattern with shared variable

Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@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
BaseTools/Source/Python/GenFds/FdfParser.py

index df287414db6f6c847669001ff47eae27a79218d6..806fdd8aa5bb487cdbb23da1ffc5ecea51927e44 100644 (file)
@@ -47,6 +47,8 @@ InputMacroDict = {}
 # All Macro values when parsing file, not replace existing Macro\r
 AllMacroList = []\r
 \r
+FileExtensionPattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)')\r
+\r
 def GetRealFileLine (File, Line):\r
     \r
     InsertedLines = 0\r
@@ -2842,8 +2844,7 @@ class FdfParser(object):
             \r
         Ext = ""\r
         if self.__GetNextToken():\r
-            Pattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)')\r
-            if Pattern.match(self.__Token):\r
+            if FileExtensionPattern.match(self.__Token):\r
                 Ext = self.__Token                            \r
                 return '.' + Ext    \r
             else:\r
index e35057931f03e9c5fd0d5add5aff775725e747ea..08429cd72affc0fe2af6335fdb5965e90603ec9f 100644 (file)
@@ -60,6 +60,7 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
 from Capsule import EFI_CERT_TYPE_PKCS7_GUID\r
 from Capsule import EFI_CERT_TYPE_RSA2048_SHA256_GUID\r
 from Common.RangeExpression import RangeExpression\r
+from Common.FdfParserLite import FileExtensionPattern\r
 \r
 ##define T_CHAR_SPACE                ' '\r
 ##define T_CHAR_NULL                 '\0'\r
@@ -3691,8 +3692,7 @@ class FdfParser:
 \r
         Ext = ""\r
         if self.__GetNextToken():\r
-            Pattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)')\r
-            if Pattern.match(self.__Token):\r
+            if FileExtensionPattern.match(self.__Token):\r
                 Ext = self.__Token\r
                 return '.' + Ext\r
             else:\r