Skip to content

Commit

Permalink
Auto merge of #130618 - m-ou-se:skip-query, r=<try>
Browse files Browse the repository at this point in the history
Skip query in get_parent_item when possible.

For HirIds with a non-zero item local id, `self.parent_owner_iter(hir_id).next()` just returns the same HirId with the item local id set to 0, but also does a query to retrieve the Node which is ignored here, which seems wasteful.
  • Loading branch information
bors committed Sep 20, 2024
2 parents 2b11f26 + 7a19b17 commit c447636
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,9 @@ impl<'hir> Map<'hir> {
/// in the HIR which is recorded by the map and is an item, either an item
/// in a module, trait, or impl.
pub fn get_parent_item(self, hir_id: HirId) -> OwnerId {
if let Some((def_id, _node)) = self.parent_owner_iter(hir_id).next() {
if hir_id.local_id.index() != 0 {
hir_id.owner
} else if let Some((def_id, _node)) = self.parent_owner_iter(hir_id).next() {
def_id
} else {
CRATE_OWNER_ID
Expand Down

0 comments on commit c447636

Please sign in to comment.