Skip to content

Commit

Permalink
perf: Speed up detection of text files
Browse files Browse the repository at this point in the history
We reduce how much of the buffer we walk twice which should speed up
large files.  We still load the entire file into memory which will still
hurt binary files.

This is part of #34.
  • Loading branch information
Ed Page committed Oct 25, 2019
1 parent ff8fce5 commit c20e8f6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion typos/src/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ impl<'d, 'p> Checks<'d, 'p> {
}

let buffer = std::fs::read(path)?;
if !explicit && !self.binary && buffer.find_byte(b'\0').is_some() {
let null_max = std::cmp::min(buffer.len(), 1024);
if !explicit && !self.binary && buffer[0..null_max].find_byte(b'\0').is_some() {
let msg = report::BinaryFile {
path,
non_exhaustive: (),
Expand Down

0 comments on commit c20e8f6

Please sign in to comment.