Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c7c306f

Browse files
committed
Do not decode span when we only need the name.
1 parent f07f1bf commit c7c306f

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,16 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
808808
&self.raw_proc_macros.unwrap()[pos]
809809
}
810810

811+
fn opt_item_name(self, item_index: DefIndex) -> Option<Symbol> {
812+
self.def_key(item_index).disambiguated_data.data.get_opt_name()
813+
}
814+
815+
fn item_name(self, item_index: DefIndex) -> Symbol {
816+
self.opt_item_name(item_index).expect("no encoded ident for item")
817+
}
818+
811819
fn opt_item_ident(self, item_index: DefIndex, sess: &Session) -> Option<Ident> {
812-
let name = self.def_key(item_index).disambiguated_data.data.get_opt_name()?;
820+
let name = self.opt_item_name(item_index)?;
813821
let span = match self.root.tables.def_ident_span.get(self, item_index) {
814822
Some(lazy_span) => lazy_span.decode((self, sess)),
815823
None => {
@@ -927,13 +935,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
927935
}
928936
}
929937

930-
fn get_variant(
931-
self,
932-
kind: &EntryKind,
933-
index: DefIndex,
934-
parent_did: DefId,
935-
sess: &Session,
936-
) -> ty::VariantDef {
938+
fn get_variant(self, kind: &EntryKind, index: DefIndex, parent_did: DefId) -> ty::VariantDef {
937939
let data = match kind {
938940
EntryKind::Variant(data) | EntryKind::Struct(data, _) | EntryKind::Union(data, _) => {
939941
data.decode(self)
@@ -953,7 +955,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
953955
let ctor_did = data.ctor.map(|index| self.local_def_id(index));
954956

955957
ty::VariantDef::new(
956-
self.item_ident(index, sess).name,
958+
self.item_name(index),
957959
variant_did,
958960
ctor_did,
959961
data.discr,
@@ -965,7 +967,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
965967
.decode(self)
966968
.map(|index| ty::FieldDef {
967969
did: self.local_def_id(index),
968-
name: self.item_ident(index, sess).name,
970+
name: self.item_name(index),
969971
vis: self.get_visibility(index),
970972
})
971973
.collect(),
@@ -995,10 +997,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
995997
.get(self, item_id)
996998
.unwrap_or_else(Lazy::empty)
997999
.decode(self)
998-
.map(|index| self.get_variant(&self.kind(index), index, did, tcx.sess))
1000+
.map(|index| self.get_variant(&self.kind(index), index, did))
9991001
.collect()
10001002
} else {
1001-
std::iter::once(self.get_variant(&kind, item_id, did, tcx.sess)).collect()
1003+
std::iter::once(self.get_variant(&kind, item_id, did)).collect()
10021004
};
10031005

10041006
tcx.alloc_adt_def(did, adt_kind, variants, repr)
@@ -1228,10 +1230,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
12281230
}
12291231
}
12301232

1231-
fn get_associated_item(self, id: DefIndex, sess: &Session) -> ty::AssocItem {
1233+
fn get_associated_item(self, id: DefIndex) -> ty::AssocItem {
12321234
let def_key = self.def_key(id);
12331235
let parent = self.local_def_id(def_key.parent.unwrap());
1234-
let ident = self.item_ident(id, sess);
1236+
let name = self.item_name(id);
12351237

12361238
let (kind, container, has_self) = match self.kind(id) {
12371239
EntryKind::AssocConst(container, _, _) => (ty::AssocKind::Const, container, false),
@@ -1244,7 +1246,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
12441246
};
12451247

12461248
ty::AssocItem {
1247-
name: ident.name,
1249+
name,
12481250
kind,
12491251
vis: self.get_visibility(id),
12501252
defaultness: container.defaultness(),
@@ -1301,7 +1303,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13011303
.get(self, id)
13021304
.unwrap_or_else(Lazy::empty)
13031305
.decode(self)
1304-
.map(move |index| respan(self.get_span(index, sess), self.item_ident(index, sess).name))
1306+
.map(move |index| respan(self.get_span(index, sess), self.item_name(index)))
13051307
}
13061308

13071309
fn get_struct_field_visibilities(self, id: DefIndex) -> impl Iterator<Item = Visibility> + 'a {

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
139139
tcx.calculate_dtor(def_id, |_,_| Ok(()))
140140
}
141141
associated_item_def_ids => { cdata.get_associated_item_def_ids(tcx, def_id.index) }
142-
associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) }
142+
associated_item => { cdata.get_associated_item(def_id.index) }
143143
impl_polarity => { cdata.get_impl_polarity(def_id.index) }
144144
coerce_unsized_info => {
145145
cdata.get_coerce_unsized_info(def_id.index).unwrap_or_else(|| {

0 commit comments

Comments
 (0)