Skip to content

Commit 1c1c591

Browse files
committed
[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.
1 parent 31ee872 commit 1c1c591

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

Lines changed: 3 additions & 4 deletions
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)