File tree 1 file changed +8
-13
lines changed 1 file changed +8
-13
lines changed Original file line number Diff line number Diff line change @@ -233,19 +233,14 @@ mod inprocess_jobserver {
233
233
impl JobServer {
234
234
pub ( super ) fn new ( ) -> Self {
235
235
// Use `NUM_JOBS` if set (it's configured by Cargo) and otherwise
236
- // just fall back to a semi-reasonable number.
237
- //
238
- // Note that we could use `num_cpus` here but it's an extra
239
- // dependency that will almost never be used, so
240
- // it's generally not too worth it.
241
- let mut parallelism = 4 ;
242
- // TODO: Use std::thread::available_parallelism as an upper bound
243
- // when MSRV is bumped.
244
- if let Ok ( amt) = var ( "NUM_JOBS" ) {
245
- if let Ok ( amt) = amt. parse ( ) {
246
- parallelism = amt;
247
- }
248
- }
236
+ // just fall back to the number of cores on the local machine.
237
+
238
+ let num_jobs = var ( "NUM_JOBS" ) . ok ( ) . and_then ( |j| j. parse :: < u32 > ( ) . ok ( ) ) ;
239
+ let parallelism = num_jobs. unwrap_or_else ( || {
240
+ std:: thread:: available_parallelism ( )
241
+ . map ( |v| usize:: from ( v) as u32 )
242
+ . unwrap_or ( 4 )
243
+ } ) ;
249
244
250
245
Self ( AtomicU32 :: new ( parallelism) )
251
246
}
You can’t perform that action at this time.
0 commit comments