[pypy-commit] pypy urlparse-unquote-faster: fix quadratic slowness of unquote (caused by buliding string with inplace addition)
kostialopuhin
noreply at buildbot.pypy.org
Tue Feb 12 12:00:40 CET 2013
Author: Konstantin Lopuhin <kostia.lopuhin at gmail.com>
Branch: urlparse-unquote-faster
Changeset: r61124:c7ea99e3b4db
Date: 2013-02-12 00:22 +0400
http://bitbucket.org/pypy/pypy/changeset/c7ea99e3b4db/
Log: fix quadratic slowness of unquote (caused by buliding string with
inplace addition)
diff --git a/lib-python/2.7/urllib.py b/lib-python/2.7/urllib.py
--- a/lib-python/2.7/urllib.py
+++ b/lib-python/2.7/urllib.py
@@ -1205,15 +1205,16 @@
# fastpath
if len(res) == 1:
return s
- s = res[0]
+ res_list = [res[0]]
for item in res[1:]:
try:
- s += _hextochr[item[:2]] + item[2:]
+ x = _hextochr[item[:2]] + item[2:]
except KeyError:
- s += '%' + item
+ x = '%' + item
except UnicodeDecodeError:
- s += unichr(int(item[:2], 16)) + item[2:]
- return s
+ x = unichr(int(item[:2], 16)) + item[2:]
+ res_list.append(x)
+ return ''.join(res_list)
def unquote_plus(s):
"""unquote('%7e/abc+def') -> '~/abc def'"""
diff --git a/lib-python/2.7/urlparse.py b/lib-python/2.7/urlparse.py
--- a/lib-python/2.7/urlparse.py
+++ b/lib-python/2.7/urlparse.py
@@ -321,15 +321,16 @@
# fastpath
if len(res) == 1:
return s
- s = res[0]
+ res_list = [res[0]]
for item in res[1:]:
try:
- s += _hextochr[item[:2]] + item[2:]
+ x = _hextochr[item[:2]] + item[2:]
except KeyError:
- s += '%' + item
+ x = '%' + item
except UnicodeDecodeError:
- s += unichr(int(item[:2], 16)) + item[2:]
- return s
+ x = unichr(int(item[:2], 16)) + item[2:]
+ res_list.append(x)
+ return ''.join(res_list)
def parse_qs(qs, keep_blank_values=0, strict_parsing=0):
"""Parse a query given as a string argument.
More information about the pypy-commit
mailing list