summaryrefslogtreecommitdiffstats
path: root/src/context.rs
diff options
context:
space:
mode:
authorLOU Xun <aquarhead@ela.build>2020-07-28 20:26:00 +0000
committerGitHub <noreply@github.com>2020-07-28 22:26:00 +0200
commit3818f901d4d1eaeac1ec45dc9172c7da7ef3ff18 (patch)
tree66e67078e372e423538321dad7f166dbd6debbea /src/context.rs
parentb8359a860a1613a4208f0021d2ee8d90236fb659 (diff)
perf: only check timeout every 256 files (#1499)
Diffstat (limited to 'src/context.rs')
-rw-r--r--src/context.rs8
1 files 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<String> = 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() {