changeset 30114:ad43458d3529

eol: store and reuse pattern matchers instead of creating in tight loop More "right" and more efficient.
author Mads Kiilerich <madski@unity3d.com>
date Sun, 09 Oct 2016 15:54:42 +0200
parents ffb682412b98
children 8e42dfde93d1
files hgext/eol.py
diffstat 1 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/eol.py	Sun Oct 09 15:42:42 2016 +0200
+++ b/hgext/eol.py	Sun Oct 09 15:54:42 2016 +0200
@@ -175,25 +175,27 @@
 
         include = []
         exclude = []
+        self.patterns = []
         for pattern, style in self.cfg.items('patterns'):
             key = style.upper()
             if key == 'BIN':
                 exclude.append(pattern)
             else:
                 include.append(pattern)
+            m = match.match(root, '', [pattern])
+            self.patterns.append((pattern, key, m))
         # This will match the files for which we need to care
         # about inconsistent newlines.
         self.match = match.match(root, '', [], include, exclude)
 
     def copytoui(self, ui):
-        for pattern, style in self.cfg.items('patterns'):
-            key = style.upper()
+        for pattern, key, m in self.patterns:
             try:
                 ui.setconfig('decode', pattern, self._decode[key], 'eol')
                 ui.setconfig('encode', pattern, self._encode[key], 'eol')
             except KeyError:
                 ui.warn(_("ignoring unknown EOL style '%s' from %s\n")
-                        % (style, self.cfg.source('patterns', pattern)))
+                        % (key, self.cfg.source('patterns', pattern)))
         # eol.only-consistent can be specified in ~/.hgrc or .hgeol
         for k, v in self.cfg.items('eol'):
             ui.setconfig('eol', k, v, 'eol')
@@ -203,10 +205,10 @@
         for f in (files or ctx.files()):
             if f not in ctx:
                 continue
-            for pattern, style in self.cfg.items('patterns'):
-                if not match.match(repo.root, '', [pattern])(f):
+            for pattern, key, m in self.patterns:
+                if not m(f):
                     continue
-                target = self._encode[style.upper()]
+                target = self._encode[key]
                 data = ctx[f].data()
                 if (target == "to-lf" and "\r\n" in data
                     or target == "to-crlf" and singlelf.search(data)):