Skip to content

Commit d33e140

Browse files
committed
lintcheck: use multithreading unless --fix or --recursive is used
1 parent 783bc62 commit d33e140

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lintcheck/src/config.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ use std::path::PathBuf;
33

44
#[derive(Clone, Debug, Parser)]
55
pub(crate) struct LintcheckConfig {
6-
/// Number of threads to use, 0 automatic choice
7-
#[clap(long = "jobs", short = 'j', value_name = "N", default_value_t = 1)]
8-
pub max_jobs: usize,
6+
/// Always defined after the config phase
7+
#[clap(
8+
long = "jobs",
9+
short = 'j',
10+
value_name = "N",
11+
help = "Number of threads to use (default: all unless --fix or --recursive)"
12+
)]
13+
pub max_jobs: Option<usize>,
914
/// Set the path for a crates.toml where lintcheck should read the sources from
1015
#[clap(
1116
long = "crates-toml",
@@ -50,9 +55,12 @@ impl LintcheckConfig {
5055
));
5156

5257
// look at the --threads arg, if 0 is passed, use the threads count
53-
if config.max_jobs == 0 {
54-
// automatic choice
55-
config.max_jobs = std::thread::available_parallelism().map_or(1, |n| n.get());
58+
if config.max_jobs.is_none() {
59+
config.max_jobs = Some(if config.fix || config.recursive {
60+
1
61+
} else {
62+
std::thread::available_parallelism().map_or(1, |n| n.get())
63+
});
5664
};
5765

5866
for lint_name in &mut config.lint_filter {

lintcheck/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@ impl Crate {
317317
// advance the atomic index by one
318318
let index = target_dir_index.fetch_add(1, Ordering::SeqCst);
319319
// "loop" the index within 0..thread_limit
320-
let thread_index = index % config.max_jobs;
320+
let thread_index = index % config.max_jobs.unwrap();
321321
let perc = (index * 100) / total_crates_to_lint;
322322

323-
if config.max_jobs == 1 {
323+
if config.max_jobs.unwrap() == 1 {
324324
println!(
325325
"{index}/{total_crates_to_lint} {perc}% Linting {} {}",
326326
&self.name, &self.version
@@ -627,7 +627,7 @@ fn main() {
627627
// order to achieve some kind of parallelism
628628

629629
rayon::ThreadPoolBuilder::new()
630-
.num_threads(config.max_jobs)
630+
.num_threads(config.max_jobs.unwrap())
631631
.build_global()
632632
.unwrap();
633633

0 commit comments

Comments
 (0)