Skip to content

Commit 6bdae9e

Browse files
committed
Auto merge of #78508 - wesleywiser:optimize_visit_scopes, r=petrochenkov
[resolve] Use `unwrap_or_else` instead of `unwrap_or` in a hot path This improves the performance of the `resolve_crate` function by 30% for a very large single file crate with auto-generated C bindings. cc `@rylev`
2 parents a53fb30 + 1c1c591 commit 6bdae9e

File tree

1 file changed

+3
-4
lines changed
  • compiler/rustc_resolve/src

1 file changed

+3
-4
lines changed

compiler/rustc_resolve/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1725,10 +1725,9 @@ impl<'a> Resolver<'a> {
17251725
Scope::MacroRules(binding.parent_macro_rules_scope)
17261726
}
17271727
MacroRulesScope::Invocation(invoc_id) => Scope::MacroRules(
1728-
self.output_macro_rules_scopes
1729-
.get(&invoc_id)
1730-
.cloned()
1731-
.unwrap_or(self.invocation_parent_scopes[&invoc_id].macro_rules),
1728+
self.output_macro_rules_scopes.get(&invoc_id).cloned().unwrap_or_else(
1729+
|| self.invocation_parent_scopes[&invoc_id].macro_rules,
1730+
),
17321731
),
17331732
MacroRulesScope::Empty => Scope::Module(module),
17341733
},

0 commit comments

Comments
 (0)