Skip to content

Commit e71af93

Browse files
Fix performance regression in LintLevelsBuilder
1 parent b488f86 commit e71af93

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

compiler/rustc_data_structures/src/unord.rs

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
159159
self.collect_stable_ord_by_key(project_to_key)
160160
}
161161

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

182+
#[inline]
181183
pub fn collect_stable_ord_by_key<K, C, P>(self, project_to_key: P) -> C
182184
where
183185
K: StableCompare,

compiler/rustc_lint/src/levels.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,13 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
10271027
}
10281028
}
10291029

1030-
if !is_crate_node {
1030+
if !is_crate_node
1031+
// Make sure we filter before collecting and sorting, so we don't
1032+
// waste time stabilizing the iteration order only to throw it away
1033+
&& self.current_specs().items().any(|(id, (_, src))| {
1034+
id.lint.crate_level_only && matches!(src, LintLevelSource::Node { .. })
1035+
})
1036+
{
10311037
for (id, &(level, ref src)) in self.current_specs().to_sorted_stable_ord() {
10321038
if !id.lint.crate_level_only {
10331039
continue;

0 commit comments

Comments
 (0)