perf: Speed up detection of text files

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.
This commit is contained in:
Ed Page 2019-10-25 15:05:34 -06:00
parent ff8fce5fb6
commit c20e8f6880

View file

@ -121,7 +121,8 @@ impl<'d, 'p> Checks<'d, 'p> {
} }
let buffer = std::fs::read(path)?; 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 { let msg = report::BinaryFile {
path, path,
non_exhaustive: (), non_exhaustive: (),