From 3818f901d4d1eaeac1ec45dc9172c7da7ef3ff18 Mon Sep 17 00:00:00 2001 From: LOU Xun Date: Tue, 28 Jul 2020 20:26:00 +0000 Subject: [PATCH] perf: only check timeout every 256 files (#1499) --- src/context.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/context.rs b/src/context.rs index 17a73c688..9076120cf 100644 --- a/src/context.rs +++ b/src/context.rs @@ -204,8 +204,12 @@ impl DirContents { let mut extensions: HashSet = HashSet::new(); fs::read_dir(base)? - .take_while(|_| SystemTime::now().duration_since(start).unwrap() < timeout) - .filter_map(Result::ok) + .enumerate() + .take_while(|(n, _)| { + n & 0xFF != 0 // only check SystemTime once every 2^8 entries + || SystemTime::now().duration_since(start).unwrap() < timeout + }) + .filter_map(|(_, entry)| entry.ok()) .for_each(|entry| { let path = PathBuf::from(entry.path().strip_prefix(base).unwrap()); if entry.path().is_dir() {