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

Commit e17b02d

Browse files
Use walkdir crate
It's more efficient than the fs::read_dir API
1 parent 5f1da8e commit e17b02d

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3805,6 +3805,7 @@ dependencies = [
38053805
"regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
38063806
"serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)",
38073807
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
3808+
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
38083809
]
38093810

38103811
[[package]]

src/tools/tidy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ regex = "1"
99
serde = { version = "1.0.8", features = ["derive"] }
1010
serde_json = "1.0.2"
1111
lazy_static = "1"
12+
walkdir = "2"

src/tools/tidy/src/lib.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This library contains the tidy lints and exposes it
44
//! to be used by tools.
55
6-
use std::fs;
6+
use walkdir::WalkDir;
77

88
use std::path::Path;
99

@@ -72,18 +72,14 @@ fn walk_many(paths: &[&Path], skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn F
7272
}
7373

7474
fn walk(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&Path)) {
75-
if let Ok(dir) = fs::read_dir(path) {
76-
for entry in dir {
77-
let entry = t!(entry);
78-
let kind = t!(entry.file_type());
79-
let path = entry.path();
80-
if kind.is_dir() {
81-
if !skip(&path) {
82-
walk(&path, skip, f);
83-
}
84-
} else {
85-
f(&path);
75+
let walker = WalkDir::new(path).into_iter()
76+
.filter_entry(|e| !skip(e.path()));
77+
for entry in walker {
78+
if let Ok(entry) = entry {
79+
if entry.file_type().is_dir() {
80+
continue;
8681
}
82+
f(&entry.path());
8783
}
8884
}
8985
}

0 commit comments

Comments
 (0)