Mercurial > hg
comparison mercurial/util.py @ 21914:10e99839a7a4
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.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Tue, 15 Jul 2014 15:14:45 -0700 |
parents | 50aad4609224 |
children | 234e4c24b980 |
comparison
equal
deleted
inserted
replaced
21913:50aad4609224 | 21914:10e99839a7a4 |
---|---|
742 return re2.compile(pat) | 742 return re2.compile(pat) |
743 except re2.error: | 743 except re2.error: |
744 pass | 744 pass |
745 return remod.compile(pat, flags) | 745 return remod.compile(pat, flags) |
746 | 746 |
747 @propertycache | |
748 def escape(self): | |
749 '''Return the version of escape corresponding to self.compile. | |
750 | |
751 This is imperfect because whether re2 or re is used for a particular | |
752 function depends on the flags, etc, but it's the best we can do. | |
753 ''' | |
754 global _re2 | |
755 if _re2 is None: | |
756 self._checkre2() | |
757 if _re2: | |
758 return re2.escape | |
759 else: | |
760 return remod.escape | |
761 | |
747 re = _re() | 762 re = _re() |
748 | 763 |
749 _fspathcache = {} | 764 _fspathcache = {} |
750 def fspath(name, root): | 765 def fspath(name, root): |
751 '''Get name in the case stored in the filesystem | 766 '''Get name in the case stored in the filesystem |