From b7d412c20ed5db4097ee2df25d56dc187bfa7dd3 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 23 Mar 2020 19:03:15 -0500 Subject: [PATCH] refactor: Calculate threading where it is needed --- src/main.rs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 94d19c5..7775bd5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,16 +96,6 @@ struct Args { verbose: clap_verbosity_flag::Verbosity, } -impl Args { - pub fn infer(mut self) -> Self { - if self.path.len() == 1 && self.path[0].is_file() { - self.threads = 1; - } - - self - } -} - #[derive(Debug, StructOpt)] #[structopt(rename_all = "kebab-case")] pub struct FileArgs { @@ -469,7 +459,7 @@ fn check_entry( } fn run() -> Result { - let args = Args::from_args().infer(); + let args = Args::from_args(); init_logging(args.verbose.log_level()); @@ -514,6 +504,9 @@ fn run() -> Result { .check_files(config.default.check_file()) .binary(config.files.binary()); + let threads = if path.is_file() { 1 } else { args.threads }; + let single_threaded = threads == 1; + let mut walk = ignore::WalkBuilder::new(path); walk.threads(args.threads) .hidden(config.files.ignore_hidden()) @@ -525,8 +518,6 @@ fn run() -> Result { let reporter = args.format.reporter(); - let single_threaded = args.threads == 1; - if args.files { if single_threaded { for entry in walk.build() {