[PATCH] match: use re2 in readpatternfile if possible

Bryan O'Sullivan bos at serpentine.com
Thu Dec 10 19:02:35 UTC 2015


# HG changeset patch
# User Bryan O'Sullivan <bos at serpentine.com>
# Date 1449194374 28800
#      Thu Dec 03 17:59:34 2015 -0800
# Node ID e41d4b2eb41eaba7ff2c1e7f4f110253574455e3
# Parent  df9b73d2d444ae82fe8d3fe6cf682a93b2c4a7ef
match: use re2 in readpatternfile if possible

This has a small, but measurable, effect on performance if a pattern
file is very large.  In an artificial test with 200,000 lines of
pattern data, using re2 reduced read time by 200 milliseconds.

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -654,9 +654,11 @@ def readpatternfile(filepath, warn):
         if "#" in line:
             global _commentre
             if not _commentre:
-                _commentre = re.compile(r'((^|[^\\])(\\\\)*)#.*')
+                _commentre = util.re.compile(r'((^|[^\\])(\\\\)*)#.*')
             # remove comments prefixed by an even number of escapes
-            line = _commentre.sub(r'\1', line)
+            m = _commentre.search(line)
+            if m:
+                line = line[:m.start(1)]
             # fixup properly escaped comments that survived the above
             line = line.replace("\\#", "#")
         line = line.rstrip()


More information about the Mercurial-devel mailing list