From: Zac Medico Date: Sat, 31 Mar 2012 23:19:04 +0000 (-0700) Subject: varexpand: optimize access to current char X-Git-Tag: v2.2.0_alpha97 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=fba4880f560a03e52857af53c722b6b2138da732;p=portage.git varexpand: optimize access to current char --- diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py index 3e7187cfd..d6ac46c83 100644 --- a/pym/portage/util/__init__.py +++ b/pym/portage/util/__init__.py @@ -660,14 +660,15 @@ def varexpand(mystring, mydict=None, error_leader=None): This would be a good bunch of code to port to C. """ numvars=0 - mystring=" "+mystring #in single, double quotes insing=0 indoub=0 - pos=1 + pos = 0 + length = len(mystring) newstring = [] - while (pos=len(mystring)): - newstring.append(mystring[pos]) + newstring.append(current) break else: - a = mystring[pos + 1] - pos = pos + 2 - if a in ("\\", "$"): - newstring.append(a) - elif a == "\n": + current = mystring[pos + 1] + pos += 2 + if current == "$": + newstring.append(current) + elif current == "\\": + 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 += 1 + elif current == "\n": pass else: newstring.append(mystring[pos - 2:pos]) continue - elif (mystring[pos]=="$") and (mystring[pos-1]!="\\"): + elif current == "$": pos=pos+1 if mystring[pos]=="{": pos=pos+1 @@ -754,11 +763,11 @@ def varexpand(mystring, mydict=None, error_leader=None): if myvarname in mydict: newstring.append(mydict[myvarname]) else: - newstring.append(mystring[pos]) - pos=pos+1 + newstring.append(current) + pos += 1 else: - newstring.append(mystring[pos]) - pos=pos+1 + newstring.append(current) + pos += 1 return "".join(newstring)