Skip to content

Commit 0b6980b

Browse files
authored
Rollup merge of rust-lang#120853 - blyxyas:no-collect, r=cjgillot
Avoid a collection and iteration on empty passes Just some mini optimization I saw in the wild. This way, we avoid a `collect` and `map` on an empty `passes`. Honestly, I don't even think this is big enough of a change to make a benchmark, but I'd still like to see results. Based on [this book](https://nnethercote.github.io/perf-book/iterators.html#collect-and-extend)
2 parents 9e5639e + 4ef1790 commit 0b6980b

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

compiler/rustc_lint/src/late.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,11 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
364364
// Note: `passes` is often empty. In that case, it's faster to run
365365
// `builtin_lints` directly rather than bundling it up into the
366366
// `RuntimeCombinedLateLintPass`.
367-
let mut passes: Vec<_> = unerased_lint_store(tcx.sess)
368-
.late_module_passes
369-
.iter()
370-
.map(|mk_pass| (mk_pass)(tcx))
371-
.collect();
372-
if passes.is_empty() {
367+
let late_module_passes = &unerased_lint_store(tcx.sess).late_module_passes;
368+
if late_module_passes.is_empty() {
373369
late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
374370
} else {
371+
let mut passes: Vec<_> = late_module_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
375372
passes.push(Box::new(builtin_lints));
376373
let pass = RuntimeCombinedLateLintPass { passes: &mut passes[..] };
377374
late_lint_mod_inner(tcx, module_def_id, context, pass);

0 commit comments

Comments
 (0)