lint: Speed up by doing fewer regex compiles.

Even though you'd think these regexes would be
cached, compiling the regex outside of looping
through lines makes a difference.

My timings are 8.4s -> 6.0s.  (You need to hack
on the linter to isolate the custom checks.)
This commit is contained in:
Steve Howell
2018-11-10 19:13:17 +00:00
committed by Tim Abbott
parent 08e44aac0d
commit f386c64759

View File

@@ -113,7 +113,7 @@ def custom_check_file(fn: str,
if exclude_fn == fn if exclude_fn == fn
} }
pattern = rule['pattern'] pattern = re.compile(rule['pattern'])
for (i, line, line_newline_stripped, line_fully_stripped) in line_tups: for (i, line, line_newline_stripped, line_fully_stripped) in line_tups:
if line_fully_stripped in exclude_lines: if line_fully_stripped in exclude_lines:
exclude_lines.remove(line_fully_stripped) exclude_lines.remove(line_fully_stripped)
@@ -125,7 +125,7 @@ def custom_check_file(fn: str,
line_to_check = line_newline_stripped line_to_check = line_newline_stripped
else: else:
raise Exception("Invalid strip rule") raise Exception("Invalid strip rule")
if re.search(pattern, line_to_check): if pattern.search(line_to_check):
if rule.get("exclude_pattern"): if rule.get("exclude_pattern"):
if re.search(rule['exclude_pattern'], line_to_check): if re.search(rule['exclude_pattern'], line_to_check):
continue continue