Reuse allocations between files
This commit is contained in:
parent
1cccf2dd4c
commit
97cffd5295
1 changed files with 6 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
use ignore::DirEntry;
|
use ignore::DirEntry;
|
||||||
|
|
||||||
use std::{fs, path::Path};
|
use std::{fs::File, io::Read, path::Path};
|
||||||
|
|
||||||
/// The default directory filter.
|
/// The default directory filter.
|
||||||
pub fn filter_dirs(path: &Path) -> bool {
|
pub fn filter_dirs(path: &Path) -> bool {
|
||||||
|
@ -48,9 +48,12 @@ pub fn walk(
|
||||||
skip: impl Send + Sync + 'static + Fn(&Path) -> bool,
|
skip: impl Send + Sync + 'static + Fn(&Path) -> bool,
|
||||||
f: &mut dyn FnMut(&DirEntry, &str),
|
f: &mut dyn FnMut(&DirEntry, &str),
|
||||||
) {
|
) {
|
||||||
|
let mut contents = Vec::new();
|
||||||
walk_no_read(path, skip, &mut |entry| {
|
walk_no_read(path, skip, &mut |entry| {
|
||||||
let contents = t!(fs::read(entry.path()), entry.path());
|
contents.clear();
|
||||||
let contents_str = match String::from_utf8(contents) {
|
let mut file = t!(File::open(entry.path()), entry.path());
|
||||||
|
t!(file.read_to_end(&mut contents), entry.path());
|
||||||
|
let contents_str = match std::str::from_utf8(&contents) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(_) => return, // skip this file
|
Err(_) => return, // skip this file
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue