mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-24 18:10:56 -05:00
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:
parent
ff8fce5fb6
commit
c20e8f6880
1 changed files with 2 additions and 1 deletions
|
@ -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: (),
|
||||||
|
|
Loading…
Reference in a new issue