Commits

Konstantin Lopuhin committed f505dfc

fix quadratic slowness of unquote (caused by buliding string with inplace addition)

Comments (0)

Files changed (2)

lib-python/2.7/urllib.py

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

lib-python/2.7/urlparse.py

     # 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.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.