Skip to content

Commit

Permalink
Rollup merge of #80643 - LingMan:unwrap, r=oli-obk
Browse files Browse the repository at this point in the history
Move variable into the only branch where it is relevant

At the `if` branch `filter` (the `let` binding) is `None` iff `filter` (the parameter) was `None`.
We can branch on the parameter, move the binding into the `if`, and the complexity of handling
`Option<Option<_>` largely dissolves.

`@rustbot` modify labels +C-cleanup +T-compiler

Note: I have no idea how hot this code is. If this method frequently gets called with a `None` filter, there might be a small perf improvement.
  • Loading branch information
JohnTitor authored Jan 5, 2021
2 parents faf8bed + af7134e commit 598d189
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,15 +1341,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
return &[];
}

// Do a reverse lookup beforehand to avoid touching the crate_num
// hash map in the loop below.
let filter = match filter.map(|def_id| self.reverse_translate_def_id(def_id)) {
Some(Some(def_id)) => Some((def_id.krate.as_u32(), def_id.index)),
Some(None) => return &[],
None => None,
};
if let Some(def_id) = filter {
// Do a reverse lookup beforehand to avoid touching the crate_num
// hash map in the loop below.
let filter = match self.reverse_translate_def_id(def_id) {
Some(def_id) => (def_id.krate.as_u32(), def_id.index),
None => return &[],
};

if let Some(filter) = filter {
if let Some(impls) = self.trait_impls.get(&filter) {
tcx.arena.alloc_from_iter(
impls.decode(self).map(|(idx, simplified_self_ty)| {
Expand Down

0 comments on commit 598d189

Please sign in to comment.