From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1SE7Zz-0000qB-8W for garchives@archives.gentoo.org; Sat, 31 Mar 2012 23:19:31 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 63C19E0A8F; Sat, 31 Mar 2012 23:19:20 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 1AF1CE0A8F for ; Sat, 31 Mar 2012 23:19:20 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 0DBE01B4013 for ; Sat, 31 Mar 2012 23:19:19 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id D0F4FE5402 for ; Sat, 31 Mar 2012 23:19:16 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1333235944.fba4880f560a03e52857af53c722b6b2138da732.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/util/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/util/__init__.py X-VCS-Directories: pym/portage/util/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: fba4880f560a03e52857af53c722b6b2138da732 X-VCS-Branch: master Date: Sat, 31 Mar 2012 23:19:16 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: f2c181a0-1b1e-4066-8572-f6f7db712bc3 X-Archives-Hash: ca0f39db3dfcfac5ec4a298d41feb96a commit: fba4880f560a03e52857af53c722b6b2138da732 Author: Zac Medico gentoo org> AuthorDate: Sat Mar 31 23:19:04 2012 +0000 Commit: Zac Medico gentoo org> CommitDate: Sat Mar 31 23:19:04 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3Dfba4880f varexpand: optimize access to current char --- pym/portage/util/__init__.py | 47 +++++++++++++++++++++++++-----------= ------ 1 files changed, 28 insertions(+), 19 deletions(-) diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py index 3e7187c..d6ac46c 100644 --- a/pym/portage/util/__init__.py +++ b/pym/portage/util/__init__.py @@ -660,14 +660,15 @@ def varexpand(mystring, mydict=3DNone, error_leader= =3DNone): This would be a good bunch of code to port to C. """ numvars=3D0 - mystring=3D" "+mystring #in single, double quotes insing=3D0 indoub=3D0 - pos=3D1 + pos =3D 0 + length =3D len(mystring) newstring =3D [] - while (pos=3Dlen(mystring)): - newstring.append(mystring[pos]) + newstring.append(current) break else: - a =3D mystring[pos + 1] - pos =3D pos + 2 - if a in ("\\", "$"): - newstring.append(a) - elif a =3D=3D "\n": + current =3D mystring[pos + 1] + pos +=3D 2 + if current =3D=3D "$": + newstring.append(current) + elif current =3D=3D "\\": + newstring.append(current) + # BUG: This spot appears buggy, but it's intended to + # be bug-for-bug compatible with existing behavior. + if pos < length and \ + mystring[pos] in ("'", '"', "$"): + newstring.append(mystring[pos]) + pos +=3D 1 + elif current =3D=3D "\n": pass else: newstring.append(mystring[pos - 2:pos]) continue - elif (mystring[pos]=3D=3D"$") and (mystring[pos-1]!=3D"\\"): + elif current =3D=3D "$": pos=3Dpos+1 if mystring[pos]=3D=3D"{": pos=3Dpos+1 @@ -754,11 +763,11 @@ def varexpand(mystring, mydict=3DNone, error_leader= =3DNone): if myvarname in mydict: newstring.append(mydict[myvarname]) else: - newstring.append(mystring[pos]) - pos=3Dpos+1 + newstring.append(current) + pos +=3D 1 else: - newstring.append(mystring[pos]) - pos=3Dpos+1 + newstring.append(current) + pos +=3D 1 =20 return "".join(newstring) =20