comparison mercurial/utils/stringutil.py @ 40684:e6c9ef5e11a0

match: provide and use a quick way to escape a single byte The previous function has a lot of overhead (including being a function). In the `_globre` case, we always escape a single byte. So we provide a dictionary dedicated to this use case. We directly use the dictionary to avoid a function call, these are expensive in Python. Again, this raise a very significant performance gain: Before: ! wall 0.059793 comb 0.060000 user 0.060000 sys 0.000000 (median of 100) After: ! wall 0.020390 comb 0.020000 user 0.020000 sys 0.000000 (median of 146) Total improvement for the full series: Before: ! wall 0.153153 comb 0.150000 user 0.150000 sys 0.000000 (median of 66) After: ! wall 0.020390 comb 0.020000 user 0.020000 sys 0.000000 (median of 146)
author Boris Feld <boris.feld@octobus.net>
date Mon, 19 Nov 2018 18:54:44 +0000
parents be57c7019c70
children 2372284d9457
comparison
equal deleted inserted replaced
40683:d7936a9dad47 40684:e6c9ef5e11a0
26 26
27 # regex special chars pulled from https://bugs.python.org/issue29995 27 # regex special chars pulled from https://bugs.python.org/issue29995
28 # which was part of Python 3.7. 28 # which was part of Python 3.7.
29 _respecial = pycompat.bytestr(b'()[]{}?*+-|^$\\.&~# \t\n\r\v\f') 29 _respecial = pycompat.bytestr(b'()[]{}?*+-|^$\\.&~# \t\n\r\v\f')
30 _regexescapemap = {ord(i): (b'\\' + i).decode('latin1') for i in _respecial} 30 _regexescapemap = {ord(i): (b'\\' + i).decode('latin1') for i in _respecial}
31 regexbytesescapemap = {i: (b'\\' + i) for i in _respecial}
31 32
32 def reescape(pat): 33 def reescape(pat):
33 """Drop-in replacement for re.escape.""" 34 """Drop-in replacement for re.escape."""
34 # NOTE: it is intentional that this works on unicodes and not 35 # NOTE: it is intentional that this works on unicodes and not
35 # bytes, as it's only possible to do the escaping with 36 # bytes, as it's only possible to do the escaping with