Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 30063:81d38478fced
util: remove the copypasta unquote function
The _urlunquote function was added back in the day to improve startup
performance, but this version is a) not compatible with Python 3 and b) has
quadratic performance issues that Python core solved eons ago.
Moreover, the function moved from urllib to urlparse (cheaper to import) *and*
that module is already imported into pycompat. As a result, removing this
function improves perf now.
Before:
! wall 0.066773 comb 0.000000 user 0.000000 sys 0.000000 (best of 100)
After:
! wall 0.065990 comb 0.000000 user 0.000000 sys 0.000000 (best of 100)
author | Martijn Pieters <mjpieters@fb.com> |
---|---|
date | Fri, 07 Oct 2016 17:06:55 +0200 |
parents | 8b89521a69ba |
children | 9b230a8e6008 |
comparison
equal
deleted
inserted
replaced
30062:940c05b25b07 | 30063:81d38478fced |
---|---|
2299 return _booleans.get(s.lower(), None) | 2299 return _booleans.get(s.lower(), None) |
2300 | 2300 |
2301 _hextochr = dict((a + b, chr(int(a + b, 16))) | 2301 _hextochr = dict((a + b, chr(int(a + b, 16))) |
2302 for a in string.hexdigits for b in string.hexdigits) | 2302 for a in string.hexdigits for b in string.hexdigits) |
2303 | 2303 |
2304 def _urlunquote(s): | |
2305 """Decode HTTP/HTML % encoding. | |
2306 | |
2307 >>> _urlunquote('abc%20def') | |
2308 'abc def' | |
2309 """ | |
2310 res = s.split('%') | |
2311 # fastpath | |
2312 if len(res) == 1: | |
2313 return s | |
2314 s = res[0] | |
2315 for item in res[1:]: | |
2316 try: | |
2317 s += _hextochr[item[:2]] + item[2:] | |
2318 except KeyError: | |
2319 s += '%' + item | |
2320 except UnicodeDecodeError: | |
2321 s += unichr(int(item[:2], 16)) + item[2:] | |
2322 return s | |
2323 | |
2324 class url(object): | 2304 class url(object): |
2325 r"""Reliable URL parser. | 2305 r"""Reliable URL parser. |
2326 | 2306 |
2327 This parses URLs and provides attributes for the following | 2307 This parses URLs and provides attributes for the following |
2328 components: | 2308 components: |
2487 # leave the query string escaped | 2467 # leave the query string escaped |
2488 for a in ('user', 'passwd', 'host', 'port', | 2468 for a in ('user', 'passwd', 'host', 'port', |
2489 'path', 'fragment'): | 2469 'path', 'fragment'): |
2490 v = getattr(self, a) | 2470 v = getattr(self, a) |
2491 if v is not None: | 2471 if v is not None: |
2492 setattr(self, a, _urlunquote(v)) | 2472 setattr(self, a, pycompat.urlparse.unquote(v)) |
2493 | 2473 |
2494 def __repr__(self): | 2474 def __repr__(self): |
2495 attrs = [] | 2475 attrs = [] |
2496 for a in ('scheme', 'user', 'passwd', 'host', 'port', 'path', | 2476 for a in ('scheme', 'user', 'passwd', 'host', 'port', 'path', |
2497 'query', 'fragment'): | 2477 'query', 'fragment'): |