From 93e54884202723255395664ac2f0926f42f09ecd Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 24 Oct 2022 11:38:20 -0400 Subject: [PATCH] walk: Simplify the code in scan() a bit --- src/walk.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/walk.rs b/src/walk.rs index 243eef9..7998282 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -49,14 +49,11 @@ pub const DEFAULT_MAX_BUFFER_TIME: Duration = Duration::from_millis(100); /// If the `--exec` argument was supplied, this will create a thread pool for executing /// jobs in parallel from a given command line and the discovered paths. Otherwise, each /// path will simply be written to standard output. -pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) -> Result { - let mut path_iter = path_vec.iter(); - let first_path_buf = path_iter - .next() - .expect("Error: Path vector can not be empty"); +pub fn scan(paths: &[PathBuf], pattern: Arc, config: Arc) -> Result { + let first_path = &paths[0]; let (tx, rx) = channel(); - let mut override_builder = OverrideBuilder::new(first_path_buf.as_path()); + let mut override_builder = OverrideBuilder::new(first_path); for pattern in &config.exclude_patterns { override_builder @@ -67,7 +64,7 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) -> R .build() .map_err(|_| anyhow!("Mismatch in exclude patterns"))?; - let mut walker = WalkBuilder::new(first_path_buf.as_path()); + let mut walker = WalkBuilder::new(first_path); walker .hidden(config.ignore_hidden) .ignore(config.read_fdignore) @@ -121,8 +118,8 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) -> R } } - for path_entry in path_iter { - walker.add(path_entry.as_path()); + for path in &paths[1..] { + walker.add(path); } let parallel_walker = walker.threads(config.threads).build_parallel();