From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.151; helo=mga17.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2673620957443 for ; Tue, 27 Mar 2018 19:48:34 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Mar 2018 19:55:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,369,1517904000"; d="scan'208";a="41846537" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga001.fm.intel.com with ESMTP; 27 Mar 2018 19:55:12 -0700 Received: from fmsmsx126.amr.corp.intel.com (10.18.125.43) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 27 Mar 2018 19:55:12 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX126.amr.corp.intel.com (10.18.125.43) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 27 Mar 2018 19:55:11 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.235]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.108]) with mapi id 14.03.0319.002; Wed, 28 Mar 2018 10:55:09 +0800 From: "Zhu, Yonghong" To: "Carsey, Jaben" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [PATCH v1 1/1] BaseTools: refactor repeated RegExp when no special searching is needed. Thread-Index: AQHTxWM3u8FAyKO1002bW75MKbiJP6Pk9T9w Date: Wed, 28 Mar 2018 02:55:08 +0000 Message-ID: References: <23da25e59e3a08bf82bb9373dc4e989f7684c5c8.1522110768.git.jaben.carsey@intel.com> In-Reply-To: <23da25e59e3a08bf82bb9373dc4e989f7684c5c8.1522110768.git.jaben.carsey@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v1 1/1] BaseTools: refactor repeated RegExp when no special searching is needed. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Mar 2018 02:48:35 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Yonghong Zhu =20 Best Regards, Zhu Yonghong -----Original Message----- From: Carsey, Jaben=20 Sent: Tuesday, March 27, 2018 8:33 AM To: edk2-devel@lists.01.org Cc: Gao, Liming ; Zhu, Yonghong Subject: [PATCH v1 1/1] BaseTools: refactor repeated RegExp when no special= searching is needed. use str.replace and try/except. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- 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/Sourc= e/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 =3D ReOffset.findall(Item) except: pass + # replace each offset, except errors for Offset in OffsetList: - if Offset in LabelDict.keys(): - Re =3D re.compile('OFFSET_OF\(%s\)' % = Offset) - Item =3D Re.sub(LabelDict[Offset], Ite= m) - else: + try: + Item =3D Item.replace('OFFSET_OF({})'.= format(Offset),LabelDict[Offset]) + except: raise BadExpression('%s not defined' %= Offset) + NewPcdValueList.append(Item) =20 AllPcdValueList =3D [] --=20 2.16.2.windows.1