Patchwork [4,of,6,V3] match: extract function that group regexps

login
register
mail settings
Submitter Boris Feld
Date Nov. 23, 2018, 2:12 p.m.
Message ID <4fa131d8a4d7d2aea452.1542982367@localhost.localdomain>
Download mbox | patch
Permalink /patch/36746/
State Accepted
Headers show

Comments

Boris Feld - Nov. 23, 2018, 2:12 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1542903949 -3600
#      Thu Nov 22 17:25:49 2018 +0100
# Node ID 4fa131d8a4d7d2aea452994458eb088e9e997df4
# Parent  1fccf5fa1c8a65654083c85107649124f0721ffe
# EXP-Topic perf-ignore
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 4fa131d8a4d7
match: extract function that group regexps

Patch

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,8 +1203,8 @@  def _buildregexmatch(kindpats, globsuffi
     OverflowError
     """
     try:
-        regex = '(?:%s)' % '|'.join([_regex(k, p, globsuffix)
-                                     for (k, p, s) in kindpats])
+        regex = _joinregexes([_regex(k, p, globsuffix)
+                               for (k, p, s) in kindpats])
         if len(regex) > MAX_RE_SIZE:
             raise OverflowError
         return regex, _rematcher(regex)