Skip to content

Commit

Permalink
Rollup merge of #120853 - blyxyas:no-collect, r=cjgillot
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
matthiaskrgr committed Feb 9, 2024
2 parents 8177c0f + 4ef1790 commit 8e1eadd
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions compiler/rustc_lint/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,11 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
// Note: `passes` is often empty. In that case, it's faster to run
// `builtin_lints` directly rather than bundling it up into the
// `RuntimeCombinedLateLintPass`.
let mut passes: Vec<_> = unerased_lint_store(tcx.sess)
.late_module_passes
.iter()
.map(|mk_pass| (mk_pass)(tcx))
.collect();
if passes.is_empty() {
let late_module_passes = &unerased_lint_store(tcx.sess).late_module_passes;
if late_module_passes.is_empty() {
late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
} else {
let mut passes: Vec<_> = late_module_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
passes.push(Box::new(builtin_lints));
let pass = RuntimeCombinedLateLintPass { passes: &mut passes[..] };
late_lint_mod_inner(tcx, module_def_id, context, pass);
Expand Down

0 comments on commit 8e1eadd

Please sign in to comment.