Skip to content

Commit

Permalink
Fix performance regression in LintLevelsBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Dec 22, 2023
1 parent b488f86 commit e71af93
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions compiler/rustc_data_structures/src/unord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
self.collect_stable_ord_by_key(project_to_key)
}

#[inline]
pub fn collect_sorted<HCX, C>(self, hcx: &HCX, cache_sort_key: bool) -> C
where
T: ToStableHashKey<HCX>,
Expand All @@ -178,6 +179,7 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
items
}

#[inline]
pub fn collect_stable_ord_by_key<K, C, P>(self, project_to_key: P) -> C
where
K: StableCompare,
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,13 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
}
}

if !is_crate_node {
if !is_crate_node
// Make sure we filter before collecting and sorting, so we don't
// waste time stabilizing the iteration order only to throw it away
&& self.current_specs().items().any(|(id, (_, src))| {
id.lint.crate_level_only && matches!(src, LintLevelSource::Node { .. })
})
{
for (id, &(level, ref src)) in self.current_specs().to_sorted_stable_ord() {
if !id.lint.crate_level_only {
continue;
Expand Down

0 comments on commit e71af93

Please sign in to comment.