Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 97cffd5

Browse files
committed
Reuse allocations between files
1 parent 1cccf2d commit 97cffd5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/tools/tidy/src/walk.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use ignore::DirEntry;
22

3-
use std::{fs, path::Path};
3+
use std::{fs::File, io::Read, path::Path};
44

55
/// The default directory filter.
66
pub fn filter_dirs(path: &Path) -> bool {
@@ -48,9 +48,12 @@ pub fn walk(
4848
skip: impl Send + Sync + 'static + Fn(&Path) -> bool,
4949
f: &mut dyn FnMut(&DirEntry, &str),
5050
) {
51+
let mut contents = Vec::new();
5152
walk_no_read(path, skip, &mut |entry| {
52-
let contents = t!(fs::read(entry.path()), entry.path());
53-
let contents_str = match String::from_utf8(contents) {
53+
contents.clear();
54+
let mut file = t!(File::open(entry.path()), entry.path());
55+
t!(file.read_to_end(&mut contents), entry.path());
56+
let contents_str = match std::str::from_utf8(&contents) {
5457
Ok(s) => s,
5558
Err(_) => return, // skip this file
5659
};

0 commit comments

Comments
 (0)