Commits

Brian Kearns  committed 46fb234 Merge

Merged in kostialopuhin/pypy/unquote-faster (pull request #119)

Make unquote from urllib and urlparse faster

  • Participants
  • Parent commits 935bd2f, 134ddde

Comments (0)

Files changed (2)

File lib-python/2.7/urllib.py

     # 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'"""

File lib-python/2.7/urlparse.py

     # 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.