Skip to content

Commit 8f53872

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 8f53872

2 files changed

Lines changed: 3 additions & 2 deletions

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()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,4 @@ allow-magic-value-types = ["bytes", "int", "str",]
173173
max-args = 13
174174
max-branches = 48
175175
max-returns = 12
176-
max-statements = 119
176+
max-statements = 120

0 commit comments

Comments
 (0)