changeset 21915:d516b6de3821

match: use util.re.escape instead of re.escape For a pathological .hgignore with over 2500 glob lines and over 200000 calls to re.escape, and with re2 available, this speeds up parsing the .hgignore from 0.75 seconds to 0.20 seconds. This causes e.g. 'hg status' with hgwatchman enabled to go from 1.02 seconds to 0.47 seconds.
author Siddharth Agarwal <sid0@fb.com>
date Tue, 15 Jul 2014 15:34:50 -0700
parents 10e99839a7a4
children 792ebd7dc5f6
files mercurial/match.py
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/match.py	Tue Jul 15 15:14:45 2014 -0700
+++ b/mercurial/match.py	Tue Jul 15 15:34:50 2014 -0700
@@ -247,7 +247,7 @@
     i, n = 0, len(pat)
     res = ''
     group = 0
-    escape = re.escape
+    escape = util.re.escape
     def peek():
         return i < n and pat[i]
     while i < n:
@@ -310,11 +310,11 @@
     if kind == 're':
         return pat
     if kind == 'path':
-        return '^' + re.escape(pat) + '(?:/|$)'
+        return '^' + util.re.escape(pat) + '(?:/|$)'
     if kind == 'relglob':
         return '(?:|.*/)' + _globre(pat) + globsuffix
     if kind == 'relpath':
-        return re.escape(pat) + '(?:/|$)'
+        return util.re.escape(pat) + '(?:/|$)'
     if kind == 'relre':
         if pat.startswith('^'):
             return pat