Skip to content

Commit 598d189

Browse files
authored
Rollup merge of #80643 - LingMan:unwrap, r=oli-obk
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.
2 parents faf8bed + af7134e commit 598d189

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1341,15 +1341,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13411341
return &[];
13421342
}
13431343

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

1352-
if let Some(filter) = filter {
13531352
if let Some(impls) = self.trait_impls.get(&filter) {
13541353
tcx.arena.alloc_from_iter(
13551354
impls.decode(self).map(|(idx, simplified_self_ty)| {

0 commit comments

Comments
 (0)