about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoshua Nelson <github@jyn.dev>2023-03-05 05:30:56 -0600
committerJoshua Nelson <github@jyn.dev>2023-03-05 05:44:13 -0600
commit97cffd52958d34536a3ee1d3e84fe4ae50b0d0aa (patch)
tree4f7d31fef5ae1c8da767bd73a87214878d0f78b6
parent1cccf2dd4cb342542a0c7d2e59445f6eedd32a85 (diff)
downloadrust-97cffd52958d34536a3ee1d3e84fe4ae50b0d0aa.tar.gz
rust-97cffd52958d34536a3ee1d3e84fe4ae50b0d0aa.zip
Reuse allocations between files
-rw-r--r--src/tools/tidy/src/walk.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/tools/tidy/src/walk.rs b/src/tools/tidy/src/walk.rs
index f7f2c647eb4..94152e75168 100644
--- a/src/tools/tidy/src/walk.rs
+++ b/src/tools/tidy/src/walk.rs
@@ -1,6 +1,6 @@
 use ignore::DirEntry;
 
-use std::{fs, path::Path};
+use std::{fs::File, io::Read, path::Path};
 
 /// The default directory filter.
 pub fn filter_dirs(path: &Path) -> bool {
@@ -48,9 +48,12 @@ pub fn walk(
     skip: impl Send + Sync + 'static + Fn(&Path) -> bool,
     f: &mut dyn FnMut(&DirEntry, &str),
 ) {
+    let mut contents = Vec::new();
     walk_no_read(path, skip, &mut |entry| {
-        let contents = t!(fs::read(entry.path()), entry.path());
-        let contents_str = match String::from_utf8(contents) {
+        contents.clear();
+        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,
             Err(_) => return, // skip this file
         };