From 7c64788e85b4dee922e3251730bb004cdd3ad67e Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 25 Oct 2019 16:37:09 -0600 Subject: [PATCH] perf: Multi-threaded spell checking Fixes #7 --- src/main.rs | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index c79e178a8..d95d12076 100644 --- a/src/main.rs +++ b/src/main.rs @@ -354,15 +354,31 @@ fn run() -> Result { .git_ignore(config.files.ignore_vcs()) .git_exclude(config.files.ignore_vcs()) .parents(config.files.ignore_parent()); - for entry in walk.build() { - match check_entry(entry, &args, &checks) { - Ok(true) => typos_found = true, - Err(err) => { - args.format.report()(err.to_string().into()); - errors_found = true + if args.threads == 1 { + for entry in walk.build() { + match check_entry(entry, &args, &checks) { + Ok(true) => typos_found = true, + Err(err) => { + args.format.report()(err.to_string().into()); + errors_found = true + } + _ => (), } - _ => (), } + } else { + walk.build_parallel().run(|| { + Box::new(|entry: Result| { + match check_entry(entry, &args, &checks) { + Ok(true) => typos_found = true, + Err(err) => { + args.format.report()(err.to_string().into()); + errors_found = true + } + _ => (), + } + ignore::WalkState::Continue + }) + }); } }