Skip to content

Commit

Permalink
Do not decode span when we only need the name.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Feb 19, 2022
1 parent f07f1bf commit c7c306f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
34 changes: 18 additions & 16 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Expand Up @@ -808,8 +808,16 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
&self.raw_proc_macros.unwrap()[pos]
}

fn opt_item_name(self, item_index: DefIndex) -> Option<Symbol> {
self.def_key(item_index).disambiguated_data.data.get_opt_name()
}

fn item_name(self, item_index: DefIndex) -> Symbol {
self.opt_item_name(item_index).expect("no encoded ident for item")
}

fn opt_item_ident(self, item_index: DefIndex, sess: &Session) -> Option<Ident> {
let name = self.def_key(item_index).disambiguated_data.data.get_opt_name()?;
let name = self.opt_item_name(item_index)?;
let span = match self.root.tables.def_ident_span.get(self, item_index) {
Some(lazy_span) => lazy_span.decode((self, sess)),
None => {
Expand Down Expand Up @@ -927,13 +935,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}
}

fn get_variant(
self,
kind: &EntryKind,
index: DefIndex,
parent_did: DefId,
sess: &Session,
) -> ty::VariantDef {
fn get_variant(self, kind: &EntryKind, index: DefIndex, parent_did: DefId) -> ty::VariantDef {
let data = match kind {
EntryKind::Variant(data) | EntryKind::Struct(data, _) | EntryKind::Union(data, _) => {
data.decode(self)
Expand All @@ -953,7 +955,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
let ctor_did = data.ctor.map(|index| self.local_def_id(index));

ty::VariantDef::new(
self.item_ident(index, sess).name,
self.item_name(index),
variant_did,
ctor_did,
data.discr,
Expand All @@ -965,7 +967,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.decode(self)
.map(|index| ty::FieldDef {
did: self.local_def_id(index),
name: self.item_ident(index, sess).name,
name: self.item_name(index),
vis: self.get_visibility(index),
})
.collect(),
Expand Down Expand Up @@ -995,10 +997,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.get(self, item_id)
.unwrap_or_else(Lazy::empty)
.decode(self)
.map(|index| self.get_variant(&self.kind(index), index, did, tcx.sess))
.map(|index| self.get_variant(&self.kind(index), index, did))
.collect()
} else {
std::iter::once(self.get_variant(&kind, item_id, did, tcx.sess)).collect()
std::iter::once(self.get_variant(&kind, item_id, did)).collect()
};

tcx.alloc_adt_def(did, adt_kind, variants, repr)
Expand Down Expand Up @@ -1228,10 +1230,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}
}

fn get_associated_item(self, id: DefIndex, sess: &Session) -> ty::AssocItem {
fn get_associated_item(self, id: DefIndex) -> ty::AssocItem {
let def_key = self.def_key(id);
let parent = self.local_def_id(def_key.parent.unwrap());
let ident = self.item_ident(id, sess);
let name = self.item_name(id);

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

ty::AssocItem {
name: ident.name,
name,
kind,
vis: self.get_visibility(id),
defaultness: container.defaultness(),
Expand Down Expand Up @@ -1301,7 +1303,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.get(self, id)
.unwrap_or_else(Lazy::empty)
.decode(self)
.map(move |index| respan(self.get_span(index, sess), self.item_ident(index, sess).name))
.map(move |index| respan(self.get_span(index, sess), self.item_name(index)))
}

fn get_struct_field_visibilities(self, id: DefIndex) -> impl Iterator<Item = Visibility> + 'a {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Expand Up @@ -139,7 +139,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
tcx.calculate_dtor(def_id, |_,_| Ok(()))
}
associated_item_def_ids => { cdata.get_associated_item_def_ids(tcx, def_id.index) }
associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) }
associated_item => { cdata.get_associated_item(def_id.index) }
impl_polarity => { cdata.get_impl_polarity(def_id.index) }
coerce_unsized_info => {
cdata.get_coerce_unsized_info(def_id.index).unwrap_or_else(|| {
Expand Down

0 comments on commit c7c306f

Please sign in to comment.