[pypy-commit] pypy default: Merged in kostialopuhin/pypy/unquote-faster (pull request #119)
bdkearns
noreply at buildbot.pypy.org
Tue Feb 12 14:07:34 CET 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r61135:46fb234140b9
Date: 2013-02-12 05:07 -0800
http://bitbucket.org/pypy/pypy/changeset/46fb234140b9/
Log: Merged in kostialopuhin/pypy/unquote-faster (pull request #119)
Make unquote from urllib and urlparse faster
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,17 @@
# fastpath
if len(res) == 1:
return s
- s = res[0]
- for item in res[1:]:
+ res_list = [res[0]]
+ for j in xrange(1, len(res)):
+ item = res[j]
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,17 @@
# fastpath
if len(res) == 1:
return s
- s = res[0]
- for item in res[1:]:
+ res_list = [res[0]]
+ for j in xrange(1, len(res)):
+ item = res[j]
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