public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v1 1/1] BaseTools: refactor repeated RegExp when no special searching is needed.
       [not found] <cover.1522110768.git.jaben.carsey@intel.com>
@ 2018-03-27  0:33 ` Jaben Carsey
  2018-03-28  2:55   ` Zhu, Yonghong
  0 siblings, 1 reply; 2+ messages in thread
From: Jaben Carsey @ 2018-03-27  0:33 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

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>
---
 BaseTools/Source/Python/Common/Expression.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py
index 4f0f377f3788..b7500bff9051 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -938,12 +938,13 @@ class ValueExpressionEx(ValueExpression):
                                 OffsetList = ReOffset.findall(Item)
                             except:
                                 pass
+                            # replace each offset, except errors
                             for Offset in OffsetList:
-                                if Offset in LabelDict.keys():
-                                    Re = re.compile('OFFSET_OF\(%s\)' % Offset)
-                                    Item = Re.sub(LabelDict[Offset], Item)
-                                else:
+                                try:
+                                    Item = Item.replace('OFFSET_OF({})'.format(Offset),LabelDict[Offset])
+                                except:
                                     raise BadExpression('%s not defined' % Offset)
+
                             NewPcdValueList.append(Item)
 
                         AllPcdValueList = []
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v1 1/1] BaseTools: refactor repeated RegExp when no special searching is needed.
  2018-03-27  0:33 ` [PATCH v1 1/1] BaseTools: refactor repeated RegExp when no special searching is needed Jaben Carsey
@ 2018-03-28  2:55   ` Zhu, Yonghong
  0 siblings, 0 replies; 2+ messages in thread
From: Zhu, Yonghong @ 2018-03-28  2:55 UTC (permalink / raw)
  To: Carsey, Jaben, edk2-devel@lists.01.org; +Cc: Gao, Liming, Zhu, Yonghong

Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com> 

Best Regards,
Zhu Yonghong


-----Original Message-----
From: Carsey, Jaben 
Sent: Tuesday, March 27, 2018 8:33 AM
To: edk2-devel@lists.01.org
Cc: Gao, Liming <liming.gao@intel.com>; Zhu, Yonghong <yonghong.zhu@intel.com>
Subject: [PATCH v1 1/1] BaseTools: refactor repeated RegExp when no special searching is needed.

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>
---
 BaseTools/Source/Python/Common/Expression.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py
index 4f0f377f3788..b7500bff9051 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -938,12 +938,13 @@ class ValueExpressionEx(ValueExpression):
                                 OffsetList = ReOffset.findall(Item)
                             except:
                                 pass
+                            # replace each offset, except errors
                             for Offset in OffsetList:
-                                if Offset in LabelDict.keys():
-                                    Re = re.compile('OFFSET_OF\(%s\)' % Offset)
-                                    Item = Re.sub(LabelDict[Offset], Item)
-                                else:
+                                try:
+                                    Item = Item.replace('OFFSET_OF({})'.format(Offset),LabelDict[Offset])
+                                except:
                                     raise BadExpression('%s not defined' % Offset)
+
                             NewPcdValueList.append(Item)
 
                         AllPcdValueList = []
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-03-28  2:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1522110768.git.jaben.carsey@intel.com>
2018-03-27  0:33 ` [PATCH v1 1/1] BaseTools: refactor repeated RegExp when no special searching is needed Jaben Carsey
2018-03-28  2:55   ` Zhu, Yonghong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox