[PATCH 2 of 2 v2] match: use re2 in readpatternfile if possible

Augie Fackler raf at durin42.com
Fri Dec 11 09:57:49 CST 2015


On Thu, Dec 10, 2015 at 09:34:02PM -0800, Bryan O'Sullivan wrote:
> # HG changeset patch
> # User Bryan O'Sullivan <bos at serpentine.com>
> # Date 1449812035 28800
> #      Thu Dec 10 21:33:55 2015 -0800
> # Node ID 18f300e9ca45cdae3575d1860251929abf07b42c
> # Parent  dea2f8f8a033c13083fe04609bf014b2f58dfcf3
> match: use re2 in readpatternfile if possible

Sure, queued these.

>
> 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.end(1)]
>              # fixup properly escaped comments that survived the above
>              line = line.replace("\\#", "#")
>          line = line.rstrip()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list