Skip to content

Commit

Permalink
Box Typedef to reduce the size of ItemKind
Browse files Browse the repository at this point in the history
This reduces the size from

```
[src/librustdoc/lib.rs:102] std::mem::size_of::<Item>() = 520
[src/librustdoc/lib.rs:102] std::mem::size_of::<ItemKind>() = 248
```

to

```
[src/librustdoc/lib.rs:102] std::mem::size_of::<Item>() = 432
[src/librustdoc/lib.rs:102] std::mem::size_of::<ItemKind>() = 160
```
  • Loading branch information
jyn514 committed Dec 12, 2020
1 parent c042b33 commit 5a24faf
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ crate fn try_inline(
Res::Def(DefKind::TyAlias, did) => {
record_extern_fqn(cx, did, clean::TypeKind::Typedef);
ret.extend(build_impls(cx, Some(parent_module), did, attrs));
clean::TypedefItem(build_type_alias(cx, did), false)
clean::TypedefItem(box build_type_alias(cx, did), false)
}
Res::Def(DefKind::Enum, did) => {
record_extern_fqn(cx, did, clean::TypeKind::Enum);
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ impl Clean<Item> for hir::ImplItem<'_> {
hir::ImplItemKind::TyAlias(ref ty) => {
let type_ = ty.clean(cx);
let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did));
TypedefItem(Typedef { type_, generics: Generics::default(), item_type }, true)
TypedefItem(box Typedef { type_, generics: Generics::default(), item_type }, true)
}
};
Item::from_def_id_and_parts(local_did, Some(self.ident.name.clean(cx)), inner, cx)
Expand Down Expand Up @@ -1270,7 +1270,7 @@ impl Clean<Item> for ty::AssocItem {
let type_ = cx.tcx.type_of(self.def_id).clean(cx);
let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did));
TypedefItem(
Typedef {
box Typedef {
type_,
generics: Generics { params: Vec::new(), where_predicates: Vec::new() },
item_type,
Expand Down Expand Up @@ -1981,7 +1981,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
let rustdoc_ty = ty.clean(cx);
let item_type = rustdoc_ty.def_id().and_then(|did| inline::build_ty(cx, did));
TypedefItem(
Typedef { type_: rustdoc_ty, generics: generics.clean(cx), item_type },
box Typedef { type_: rustdoc_ty, generics: generics.clean(cx), item_type },
false,
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ crate enum ItemKind {
EnumItem(Enum),
FunctionItem(Box<Function>),
ModuleItem(Module),
TypedefItem(Typedef, bool /* is associated type */),
TypedefItem(Box<Typedef>, bool /* is associated type */),
OpaqueTyItem(OpaqueTy),
StaticItem(Static),
ConstantItem(Constant),
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3561,7 +3561,7 @@ fn render_deref_methods(
.items
.iter()
.find_map(|item| match item.kind {
clean::TypedefItem(ref t, true) => Some(match *t {
clean::TypedefItem(ref t, true) => Some(match **t {
clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_),
_ => (&t.type_, &t.type_),
}),
Expand Down Expand Up @@ -4239,7 +4239,7 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
{
if let Some((target, real_target)) =
impl_.inner_impl().items.iter().find_map(|item| match item.kind {
clean::TypedefItem(ref t, true) => Some(match *t {
clean::TypedefItem(ref t, true) => Some(match **t {
clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_),
_ => (&t.type_, &t.type_),
}),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl From<clean::ItemKind> for ItemEnum {
StaticItem(s) => ItemEnum::StaticItem(s.into()),
ForeignStaticItem(s) => ItemEnum::StaticItem(s.into()),
ForeignTypeItem => ItemEnum::ForeignTypeItem,
TypedefItem(t, _) => ItemEnum::TypedefItem(t.into()),
TypedefItem(box t, _) => ItemEnum::TypedefItem(t.into()),
OpaqueTyItem(t) => ItemEnum::OpaqueTyItem(t.into()),
ConstantItem(c) => ItemEnum::ConstantItem(c.into()),
MacroItem(m) => ItemEnum::MacroItem(m.source),
Expand Down

0 comments on commit 5a24faf

Please sign in to comment.