Skip to content

Commit

Permalink
Auto merge of #78508 - wesleywiser:optimize_visit_scopes, r=petrochenkov
Browse files Browse the repository at this point in the history
[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`
  • Loading branch information
bors committed Oct 29, 2020
2 parents a53fb30 + 1c1c591 commit 6bdae9e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1725,10 +1725,9 @@ impl<'a> Resolver<'a> {
Scope::MacroRules(binding.parent_macro_rules_scope)
}
MacroRulesScope::Invocation(invoc_id) => Scope::MacroRules(
self.output_macro_rules_scopes
.get(&invoc_id)
.cloned()
.unwrap_or(self.invocation_parent_scopes[&invoc_id].macro_rules),
self.output_macro_rules_scopes.get(&invoc_id).cloned().unwrap_or_else(
|| self.invocation_parent_scopes[&invoc_id].macro_rules,
),
),
MacroRulesScope::Empty => Scope::Module(module),
},
Expand Down

0 comments on commit 6bdae9e

Please sign in to comment.