mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 07:17:55 +03:00
util.re: add an escape method
The escape method in at least one of the modules called 're2' is in C. This means it is significantly faster than the Python code written in 're'. An upcoming patch will have benchmarks.
This commit is contained in:
parent
dd9e1b721a
commit
2b459094e1
@ -744,6 +744,21 @@ class _re(object):
|
||||
pass
|
||||
return remod.compile(pat, flags)
|
||||
|
||||
@propertycache
|
||||
def escape(self):
|
||||
'''Return the version of escape corresponding to self.compile.
|
||||
|
||||
This is imperfect because whether re2 or re is used for a particular
|
||||
function depends on the flags, etc, but it's the best we can do.
|
||||
'''
|
||||
global _re2
|
||||
if _re2 is None:
|
||||
self._checkre2()
|
||||
if _re2:
|
||||
return re2.escape
|
||||
else:
|
||||
return remod.escape
|
||||
|
||||
re = _re()
|
||||
|
||||
_fspathcache = {}
|
||||
|
Loading…
Reference in New Issue
Block a user