rustc_metadata: Make attribute decoding slightly faster and stricter
Rename `CStore::item_attrs` -> `CStore::item_attrs_untracked` top follow conventions
This commit is contained in:
parent
636fd495c8
commit
4c6120c386
4 changed files with 24 additions and 22 deletions
|
@ -1309,24 +1309,26 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
|||
|
||||
fn get_item_attrs(
|
||||
&'a self,
|
||||
node_id: DefIndex,
|
||||
id: DefIndex,
|
||||
sess: &'a Session,
|
||||
) -> impl Iterator<Item = ast::Attribute> + 'a {
|
||||
// The attributes for a tuple struct/variant are attached to the definition, not the ctor;
|
||||
// we assume that someone passing in a tuple struct ctor is actually wanting to
|
||||
// look at the definition
|
||||
let def_key = self.def_key(node_id);
|
||||
let item_id = if def_key.disambiguated_data.data == DefPathData::Ctor {
|
||||
def_key.parent.unwrap()
|
||||
} else {
|
||||
node_id
|
||||
};
|
||||
|
||||
self.root
|
||||
.tables
|
||||
.attributes
|
||||
.get(self, item_id)
|
||||
.unwrap_or_else(Lazy::empty)
|
||||
.get(self, id)
|
||||
.unwrap_or_else(|| {
|
||||
// Structure and variant constructors don't have any attributes encoded for them,
|
||||
// but we assume that someone passing a constructor ID actually wants to look at
|
||||
// the attributes on the corresponding struct or variant.
|
||||
let def_key = self.def_key(id);
|
||||
assert_eq!(def_key.disambiguated_data.data, DefPathData::Ctor);
|
||||
let parent_id = def_key.parent.expect("no parent for a constructor");
|
||||
self.root
|
||||
.tables
|
||||
.attributes
|
||||
.get(self, parent_id)
|
||||
.expect("no encoded attributes for a structure or variant")
|
||||
})
|
||||
.decode((self, sess))
|
||||
}
|
||||
|
||||
|
|
|
@ -145,9 +145,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
|||
lookup_deprecation_entry => {
|
||||
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
|
||||
}
|
||||
item_attrs => { tcx.arena.alloc_from_iter(
|
||||
cdata.get_item_attrs(def_id.index, tcx.sess)
|
||||
) }
|
||||
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
|
||||
fn_arg_names => { cdata.get_fn_param_names(tcx, def_id.index) }
|
||||
rendered_const => { cdata.get_rendered_const(def_id.index) }
|
||||
impl_parent => { cdata.get_parent_impl(def_id.index) }
|
||||
|
@ -470,7 +468,7 @@ impl CStore {
|
|||
self.get_crate_data(cnum).num_def_ids()
|
||||
}
|
||||
|
||||
pub fn item_attrs(&self, def_id: DefId, sess: &Session) -> Vec<ast::Attribute> {
|
||||
pub fn item_attrs_untracked(&self, def_id: DefId, sess: &Session) -> Vec<ast::Attribute> {
|
||||
self.get_crate_data(def_id.krate).get_item_attrs(def_id.index, sess).collect()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue