[PATCH 4 of 6 V2] match: extract function that group regexps

Martin von Zweigbergk martinvonz at google.com
Fri Nov 23 02:26:53 EST 2018


On Thu, Nov 22, 2018 at 2:23 PM Boris Feld <boris.feld at octobus.net> wrote:

> # HG changeset patch
> # User Boris Feld <boris.feld at octobus.net>
> # Date 1542903949 -3600
> #      Thu Nov 22 17:25:49 2018 +0100
> # Node ID 4628c3cf1fc1052ca25296c8c1a42c4502b59dc9
> # Parent  b702174979d09090d5e5081d09755cbb74540ff0
> # EXP-Topic perf-ignore-2
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r
> 4628c3cf1fc1
> match: extract function that group regexps
>
> diff --git a/mercurial/match.py b/mercurial/match.py
> --- a/mercurial/match.py
> +++ b/mercurial/match.py
> @@ -1186,6 +1186,10 @@ def _buildmatch(kindpats, globsuffix, li
>
>  MAXRESIZE = 20000
>
> +def _groupregexps(regexps):
>

The name suggests to me that it produces a list of lists or something like
that, but it returns a single string. Something like "_joinregexps" seems
clearer (maybe also s/exps/exes/ to match existing function names and
variable names).


> +    """gather multiple regexps into a single one"""
> +    return '(?:%s)' % '|'.join(regexps)
> +
>  def _buildregexmatch(kindpats, globsuffix):
>      """Build a match function from a list of kinds and kindpats,
>      return regexp string and a matcher function.
> @@ -1199,8 +1203,8 @@ def _buildregexmatch(kindpats, globsuffi
>      OverflowError
>      """
>      try:
> -        regex = '(?:%s)' % '|'.join([_regex(k, p, globsuffix)
> -                                     for (k, p, s) in kindpats])
> +        regex = _groupregexps([_regex(k, p, globsuffix)
> +                               for (k, p, s) in kindpats])
>          if len(regex) > MAXRESIZE:
>              raise OverflowError
>          return regex, _rematcher(regex)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20181122/ff56e403/attachment.html>


More information about the Mercurial-devel mailing list