# HG changeset patch # User Martijn Pieters <mjpiet...@fb.com> # Date 1475852815 -7200 # Fri Oct 07 17:06:55 2016 +0200 # Node ID 6d09435aa2e217f6514da8b3d6ae5b78934a19ed # Parent 91a3c58ecf938ed675f5364b88f0d663f12b0047 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) diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -2297,30 +2297,6 @@ """ return _booleans.get(s.lower(), None) -_hexdig = '0123456789ABCDEFabcdef' -_hextochr = dict((a + b, chr(int(a + b, 16))) - for a in _hexdig for b in _hexdig) - -def _urlunquote(s): - """Decode HTTP/HTML % encoding. - - >>> _urlunquote('abc%20def') - 'abc def' - """ - res = s.split('%') - # fastpath - if len(res) == 1: - return s - s = res[0] - for item in res[1:]: - try: - s += _hextochr[item[:2]] + item[2:] - except KeyError: - s += '%' + item - except UnicodeDecodeError: - s += unichr(int(item[:2], 16)) + item[2:] - return s - class url(object): r"""Reliable URL parser. @@ -2489,7 +2465,7 @@ 'path', 'fragment'): v = getattr(self, a) if v is not None: - setattr(self, a, _urlunquote(v)) + setattr(self, a, pycompat.urlparse.unquote(v)) def __repr__(self): attrs = [] _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel