Patchwork [1,of,5,V4] match: extract a literal constant into a symbolic one

login
register
mail settings
Submitter Boris Feld
Date Dec. 1, 2018, 12:07 p.m.
Message ID <cd8a3de2d43af89b3db6.1543666051@pc62.home>
Download mbox | patch
Permalink /patch/36893/
State Accepted
Headers show

Comments

Boris Feld - Dec. 1, 2018, 12:07 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1542903632 -3600
#      Thu Nov 22 17:20:32 2018 +0100
# Node ID cd8a3de2d43af89b3db66f6c539a11ef80feb5a2
# Parent  7e6834ade51d98da575cfbeef651fc8a465c38b8
# EXP-Topic perf-ignore
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r cd8a3de2d43a
match: extract a literal constant into a symbolic one

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -1184,13 +1184,15 @@  def _buildmatch(kindpats, globsuffix, li
     else:
         return regex, lambda f: any(mf(f) for mf in matchfuncs)
 
+MAX_RE_SIZE = 20000
+
 def _buildregexmatch(kindpats, globsuffix):
     """Build a match function from a list of kinds and kindpats,
     return regexp string and a matcher function."""
     try:
         regex = '(?:%s)' % '|'.join([_regex(k, p, globsuffix)
                                      for (k, p, s) in kindpats])
-        if len(regex) <= 20000:
+        if len(regex) <= MAX_RE_SIZE:
             return regex, _rematcher(regex)
         # We're using a Python with a tiny regex engine and we
         # made it explode, so we'll divide the pattern list in two