[PATCH 3 of 5 V4] match: extract function that group regexps

Boris Feld boris.feld at octobus.net
Sat Dec 1 07:07:33 EST 2018


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1542903949 -3600
#      Thu Nov 22 17:25:49 2018 +0100
# Node ID 066912081df7b43ed271bea4475e35661e16c1cf
# Parent  062da9819592bc5abd87b9a2e00739bb6729015d
# EXP-Topic perf-ignore
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 066912081df7
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
 
 MAX_RE_SIZE = 20000
 
+def _joinregexes(regexps):
+    """gather multiple regular expressions 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,7 +1203,7 @@ def _buildregexmatch(kindpats, globsuffi
     OverflowError
     """
     try:
-        regex = '(?:%s)' % '|'.join([_regex(k, p, globsuffix)
+        regex = _joinregexes([_regex(k, p, globsuffix)
                                      for (k, p, s) in kindpats])
         if len(regex) <= MAX_RE_SIZE:
             return regex, _rematcher(regex)


More information about the Mercurial-devel mailing list