Skip to content

Commit 86bf4d7

Browse files
committed
Speed up spellchecking by ignoring whitespace-only lines
Whitespace only lines cannot have typos in them at all on account of not containing any words. Nevertheless, codespell did not exit early on them causing quite some overhead. By special-casing empty and whitespace only, it is possible to reduce the runtime from ~5.4s to ~5.0s on the corpus mentioned in #3419.
1 parent 73b7b5e commit 86bf4d7

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

codespell_lib/_codespell.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,8 @@ def parse_file(
946946
return bad_count
947947

948948
for i, line in enumerate(lines):
949-
if line.rstrip() in exclude_lines:
949+
line = line.rstrip()
950+
if not line or line in exclude_lines:
950951
continue
951952

952953
extra_words_to_ignore = set()

0 commit comments

Comments
 (0)