rustdoc: Store DefId's in ItemId on heap for decreasing Item's size
This commit is contained in:
parent
acd4dc2d0c
commit
45d3daece3
16 changed files with 115 additions and 109 deletions
|
|
@ -30,7 +30,7 @@ impl JsonRenderer<'_> {
|
|||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|clean::ItemLink { link, did, .. }| {
|
||||
did.map(|did| (link.clone(), from_item_id(did.into())))
|
||||
did.map(|did| (link.clone(), from_item_id(&did.into())))
|
||||
})
|
||||
.collect();
|
||||
let docs = item.attrs.collapsed_doc_value();
|
||||
|
|
@ -41,14 +41,15 @@ impl JsonRenderer<'_> {
|
|||
.map(rustc_ast_pretty::pprust::attribute_to_string)
|
||||
.collect();
|
||||
let span = item.span(self.tcx);
|
||||
let clean::Item { name, attrs: _, kind: _, visibility, def_id, cfg: _ } = item;
|
||||
let clean::Item { name, attrs: _, kind: _, visibility, ref def_id, cfg: _ } = item;
|
||||
let def_id = def_id.clone();
|
||||
let inner = match *item.kind {
|
||||
clean::StrippedItem(_) => return None,
|
||||
_ => from_clean_item(item, self.tcx),
|
||||
};
|
||||
Some(Item {
|
||||
id: from_item_id(def_id),
|
||||
crate_id: def_id.krate().as_u32(),
|
||||
id: from_item_id(&def_id),
|
||||
name: name.map(|sym| sym.to_string()),
|
||||
span: self.convert_span(span),
|
||||
visibility: self.convert_visibility(visibility),
|
||||
|
|
@ -86,7 +87,7 @@ impl JsonRenderer<'_> {
|
|||
Inherited => Visibility::Default,
|
||||
Restricted(did) if did.index == CRATE_DEF_INDEX => Visibility::Crate,
|
||||
Restricted(did) => Visibility::Restricted {
|
||||
parent: from_item_id(did.into()),
|
||||
parent: from_item_id(&did.into()),
|
||||
path: self.tcx.def_path(did).to_string_no_crate_verbose(),
|
||||
},
|
||||
}
|
||||
|
|
@ -170,7 +171,7 @@ impl FromWithTcx<clean::TypeBindingKind> for TypeBindingKind {
|
|||
}
|
||||
}
|
||||
|
||||
crate fn from_item_id(did: ItemId) -> Id {
|
||||
crate fn from_item_id(did: &ItemId) -> Id {
|
||||
match did {
|
||||
ItemId::DefId(did) => Id(format!("{}:{}", did.krate.as_u32(), u32::from(did.index))),
|
||||
_ => todo!("how should json ItemId's be represented?"),
|
||||
|
|
@ -373,7 +374,7 @@ impl FromWithTcx<clean::Type> for Type {
|
|||
match ty {
|
||||
ResolvedPath { path, did, is_generic: _ } => Type::ResolvedPath {
|
||||
name: path.whole_name(),
|
||||
id: from_item_id(did.into()),
|
||||
id: from_item_id(&did.into()),
|
||||
args: path.segments.last().map(|args| Box::new(args.clone().args.into_tcx(tcx))),
|
||||
param_names: Vec::new(),
|
||||
},
|
||||
|
|
@ -385,7 +386,7 @@ impl FromWithTcx<clean::Type> for Type {
|
|||
|
||||
Type::ResolvedPath {
|
||||
name: path.whole_name(),
|
||||
id: from_item_id(id.into()),
|
||||
id: from_item_id(&id.into()),
|
||||
args: path
|
||||
.segments
|
||||
.last()
|
||||
|
|
@ -566,13 +567,13 @@ impl FromWithTcx<clean::Import> for Import {
|
|||
Simple(s) => Import {
|
||||
source: import.source.path.whole_name(),
|
||||
name: s.to_string(),
|
||||
id: import.source.did.map(ItemId::from).map(from_item_id),
|
||||
id: import.source.did.map(ItemId::from).as_ref().map(from_item_id),
|
||||
glob: false,
|
||||
},
|
||||
Glob => Import {
|
||||
source: import.source.path.whole_name(),
|
||||
name: import.source.path.last_name().to_string(),
|
||||
id: import.source.did.map(ItemId::from).map(from_item_id),
|
||||
id: import.source.did.map(ItemId::from).as_ref().map(from_item_id),
|
||||
glob: true,
|
||||
},
|
||||
}
|
||||
|
|
@ -666,5 +667,5 @@ impl FromWithTcx<ItemType> for ItemKind {
|
|||
}
|
||||
|
||||
fn ids(items: impl IntoIterator<Item = clean::Item>) -> Vec<Id> {
|
||||
items.into_iter().filter(|x| !x.is_stripped()).map(|i| from_item_id(i.def_id)).collect()
|
||||
items.into_iter().filter(|x| !x.is_stripped()).map(|i| from_item_id(&i.def_id)).collect()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ impl JsonRenderer<'tcx> {
|
|||
.map(|i| {
|
||||
let item = &i.impl_item;
|
||||
self.item(item.clone()).unwrap();
|
||||
from_item_id(item.def_id)
|
||||
from_item_id(&item.def_id)
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
|
|
@ -71,7 +71,7 @@ impl JsonRenderer<'tcx> {
|
|||
let item = &i.impl_item;
|
||||
if item.def_id.is_local() {
|
||||
self.item(item.clone()).unwrap();
|
||||
Some(from_item_id(item.def_id))
|
||||
Some(from_item_id(&item.def_id))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
@ -91,9 +91,9 @@ impl JsonRenderer<'tcx> {
|
|||
let trait_item = &trait_item.trait_;
|
||||
trait_item.items.clone().into_iter().for_each(|i| self.item(i).unwrap());
|
||||
Some((
|
||||
from_item_id(id.into()),
|
||||
from_item_id(&id.into()),
|
||||
types::Item {
|
||||
id: from_item_id(id.into()),
|
||||
id: from_item_id(&id.into()),
|
||||
crate_id: id.krate.as_u32(),
|
||||
name: self
|
||||
.cache
|
||||
|
|
@ -161,7 +161,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
|
|||
// Flatten items that recursively store other items
|
||||
item.kind.inner_items().for_each(|i| self.item(i.clone()).unwrap());
|
||||
|
||||
let id = item.def_id;
|
||||
let id = item.def_id.clone();
|
||||
if let Some(mut new_item) = self.convert_item(item) {
|
||||
if let types::ItemEnum::Trait(ref mut t) = new_item.inner {
|
||||
t.implementors = self.get_trait_implementors(id.expect_def_id())
|
||||
|
|
@ -170,7 +170,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
|
|||
} else if let types::ItemEnum::Enum(ref mut e) = new_item.inner {
|
||||
e.impls = self.get_impls(id.expect_def_id())
|
||||
}
|
||||
let removed = self.index.borrow_mut().insert(from_item_id(id), new_item.clone());
|
||||
let removed = self.index.borrow_mut().insert(from_item_id(&id), new_item.clone());
|
||||
|
||||
// FIXME(adotinthevoid): Currently, the index is duplicated. This is a sanity check
|
||||
// to make sure the items are unique. The main place this happens is when an item, is
|
||||
|
|
@ -207,7 +207,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
|
|||
.chain(self.cache.external_paths.clone().into_iter())
|
||||
.map(|(k, (path, kind))| {
|
||||
(
|
||||
from_item_id(k.into()),
|
||||
from_item_id(&k.into()),
|
||||
types::ItemSummary {
|
||||
crate_id: k.krate.as_u32(),
|
||||
path,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue