mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 11:22:04 +00:00
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:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user