check-code: only fix patterns once
authorSimon Heimberg <simohe@besonet.ch>
Sat, 08 Jun 2013 20:20:14 +0200
changeset 19307 5443d40d524b
parent 19306 59cdd3a7e281
child 19308 84faaacbd3fa
check-code: only fix patterns once The patterns were fixed once for every file. Now only do it once when loading the file.
contrib/check-code.py
--- a/contrib/check-code.py	Fri Jun 07 16:59:59 2013 -0500
+++ b/contrib/check-code.py	Sat Jun 08 20:20:14 2013 +0200
@@ -317,6 +317,22 @@
     ('txt', r'.*\.txt$', txtfilters, txtpats),
 ]
 
+def _preparepats():
+    for c in checks:
+        failandwarn = c[-1]
+        for pats in failandwarn:
+            for i, pseq in enumerate(pats):
+                # fix-up regexes for multi-line searches
+                po = p = pseq[0]
+                # \s doesn't match \n
+                p = re.sub(r'(?<!\\)\\s', r'[ \\t]', p)
+                # [^...] doesn't match newline
+                p = re.sub(r'(?<!\\)\[\^', r'[^\\n', p)
+
+                #print po, '=>', p
+                pats[i] = (p,) + pseq[1:]
+_preparepats()
+
 class norepeatlogger(object):
     def __init__(self):
         self._lastseen = None
@@ -403,15 +419,6 @@
                 p, msg = pat
                 ignore = None
 
-            # fix-up regexes for multi-line searches
-            po = p
-            # \s doesn't match \n
-            p = re.sub(r'(?<!\\)\\s', r'[ \\t]', p)
-            # [^...] doesn't match newline
-            p = re.sub(r'(?<!\\)\[\^', r'[^\\n', p)
-
-            #print po, '=>', p
-
             pos = 0
             n = 0
             for m in re.finditer(p, post, re.MULTILINE):