Patchwork [2,of,5] check-code: compile all patterns on initialisation

login
register
mail settings
Submitter Simon Heimberg
Date June 8, 2013, 6:57 p.m.
Message ID <ddedc8623eb8287b7d5b.1370717820@lapsi.heimberg.home>
Download mbox | patch
Permalink /patch/1710/
State Accepted
Commit 84faaacbd3fab03d73dae40b839cdd71bea21ca0
Headers show

Comments

Simon Heimberg - June 8, 2013, 6:57 p.m.
# HG changeset patch
# User Simon Heimberg <simohe@besonet.ch>
# Date 1370715614 -7200
# Node ID ddedc8623eb8287b7d5bc50a6c24404a6ec39c8a
# Parent  e32bdfb08c8ff96f9f50bfb60888c187830e3ac6
check-code: compile all patterns on initialisation

They where compiled once for every checked file (when calling finditer).

Patch

diff -r e32bdfb08c8f -r ddedc8623eb8 contrib/check-code.py
--- a/contrib/check-code.py	Sam Jun 08 20:20:14 2013 +0200
+++ b/contrib/check-code.py	Sam Jun 08 20:20:14 2013 +0200
@@ -330,7 +330,7 @@ 
                 p = re.sub(r'(?<!\\)\[\^', r'[^\\n', p)
 
                 #print po, '=>', p
-                pats[i] = (p,) + pseq[1:]
+                pats[i] = (re.compile(p, re.MULTILINE),) + pseq[1:]
 _preparepats()
 
 class norepeatlogger(object):
@@ -421,7 +421,7 @@ 
 
             pos = 0
             n = 0
-            for m in re.finditer(p, post, re.MULTILINE):
+            for m in p.finditer(post):
                 if prelines is None:
                     prelines = pre.splitlines()
                     postlines = post.splitlines(True)