BaseTools: refactor repeated RegExp when no special searching is needed.
[mirror_edk2.git] / 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
+                            # replace each offset, except errors\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
+\r
                             NewPcdValueList.append(Item)\r
 \r
                         AllPcdValueList = []\r