From 109460fce2e491aae0c2f2414e2c16141d352331 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Thu, 20 Feb 2020 16:49:54 -0500 Subject: [PATCH] ignore: simplify parallel worker initialization We can just ask the channel whether any work has been loaded. Normally querying a channel for its length is a strong predictor of bugs, but in this case, we do it before we ever attempt a `recv`, so it should work. Kudos to @zsugabubus for suggesting this! --- crates/ignore/src/walk.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/ignore/src/walk.rs b/crates/ignore/src/walk.rs index ecf87b8d..0502d366 100644 --- a/crates/ignore/src/walk.rs +++ b/crates/ignore/src/walk.rs @@ -1198,7 +1198,6 @@ impl WalkParallel { let num_pending = Arc::new(AtomicUsize::new(0)); { let mut visitor = builder.build(); - let mut any_work = false; let mut paths = Vec::new().into_iter(); std::mem::swap(&mut paths, &mut self.paths); // Send the initial set of root paths to the pool of workers. Note @@ -1241,10 +1240,9 @@ impl WalkParallel { root_device: root_device, })) .unwrap(); - any_work = true; } // ... but there's no need to start workers if we don't need them. - if !any_work { + if tx.is_empty() { return; } }