BaseTools: refactor repeated RegExp when no special searching is needed.
authorCarsey, Jaben </o=Intel/ou=Americas01/cn=Workers/cn=Carsey, Jaben>
Tue, 27 Mar 2018 00:33:08 +0000 (08:33 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Thu, 29 Mar 2018 08:33:55 +0000 (16:33 +0800)
use str.replace and try/except.

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

index 09240de6978180050be22a554293ce86b38f9593..9a844b0417f203fd6c26a95fe283e81a56a2f1c3 100644 (file)
@@ -936,12 +936,13 @@ class ValueExpressionEx(ValueExpression):
                                 OffsetList = _ReOffset.findall(Item)\r
                             except:\r
                                 pass\r
                                 OffsetList = _ReOffset.findall(Item)\r
                             except:\r
                                 pass\r
+                            # replace each offset, except errors\r
                             for Offset in OffsetList:\r
                             for Offset in OffsetList:\r
-                                if Offset in LabelDict.keys():\r
-                                    Re = re.compile('OFFSET_OF\(%s\)' % Offset)\r
-                                    Item = Re.sub(LabelDict[Offset], Item)\r
-                                else:\r
+                                try:\r
+                                    Item = Item.replace('OFFSET_OF({})'.format(Offset),LabelDict[Offset])\r
+                                except:\r
                                     raise BadExpression('%s not defined' % Offset)\r
                                     raise BadExpression('%s not defined' % Offset)\r
+\r
                             NewPcdValueList.append(Item)\r
 \r
                         AllPcdValueList = []\r
                             NewPcdValueList.append(Item)\r
 \r
                         AllPcdValueList = []\r