##// END OF EJS Templates
matcher: use re2 bindings if available...
Bryan O'Sullivan -
r16943:8d08a28a default
parent child Browse files
Show More
@@ -9,6 +9,14 b' import re'
9 9 import scmutil, util, fileset
10 10 from i18n import _
11 11
12 def _rematcher(pat):
13 m = util.compilere(pat)
14 try:
15 # slightly faster, provided by facebook's re2 bindings
16 return m.test_match
17 except AttributeError:
18 return m.match
19
12 20 def _expandsets(pats, ctx):
13 21 '''convert set: patterns into a list of files in the given context'''
14 22 fset = set()
@@ -280,7 +288,7 b' def _buildregexmatch(pats, tail):'
280 288 pat = '(?:%s)' % '|'.join([_regex(k, p, tail) for (k, p) in pats])
281 289 if len(pat) > 20000:
282 290 raise OverflowError
283 return pat, re.compile(pat).match
291 return pat, _rematcher(pat)
284 292 except OverflowError:
285 293 # We're using a Python with a tiny regex engine and we
286 294 # made it explode, so we'll divide the pattern list in two
@@ -294,7 +302,7 b' def _buildregexmatch(pats, tail):'
294 302 except re.error:
295 303 for k, p in pats:
296 304 try:
297 re.compile('(?:%s)' % _regex(k, p, tail))
305 _rematcher('(?:%s)' % _regex(k, p, tail))
298 306 except re.error:
299 307 raise util.Abort(_("invalid pattern (%s): %s") % (k, p))
300 308 raise util.Abort(_("invalid pattern"))
@@ -629,6 +629,30 b' def checkcase(path):'
629 629 except OSError:
630 630 return True
631 631
632 try:
633 import re2
634 _re2 = None
635 except ImportError:
636 _re2 = False
637
638 def compilere(pat):
639 '''Compile a regular expression, using re2 if possible
640
641 For best performance, use only re2-compatible regexp features.'''
642 global _re2
643 if _re2 is None:
644 try:
645 re2.compile
646 _re2 = True
647 except ImportError:
648 _re2 = False
649 if _re2:
650 try:
651 return re2.compile(pat)
652 except re2.error:
653 pass
654 return re.compile(pat)
655
632 656 _fspathcache = {}
633 657 def fspath(name, root):
634 658 '''Get name in the case stored in the filesystem
General Comments 0
You need to be logged in to leave comments. Login now