Skip to content

Commit 5a24faf

Browse files
committed
Box Typedef to reduce the size of ItemKind
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 ```
1 parent c042b33 commit 5a24faf

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ crate fn try_inline(
7777
Res::Def(DefKind::TyAlias, did) => {
7878
record_extern_fqn(cx, did, clean::TypeKind::Typedef);
7979
ret.extend(build_impls(cx, Some(parent_module), did, attrs));
80-
clean::TypedefItem(build_type_alias(cx, did), false)
80+
clean::TypedefItem(box build_type_alias(cx, did), false)
8181
}
8282
Res::Def(DefKind::Enum, did) => {
8383
record_extern_fqn(cx, did, clean::TypeKind::Enum);

src/librustdoc/clean/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ impl Clean<Item> for hir::ImplItem<'_> {
11211121
hir::ImplItemKind::TyAlias(ref ty) => {
11221122
let type_ = ty.clean(cx);
11231123
let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did));
1124-
TypedefItem(Typedef { type_, generics: Generics::default(), item_type }, true)
1124+
TypedefItem(box Typedef { type_, generics: Generics::default(), item_type }, true)
11251125
}
11261126
};
11271127
Item::from_def_id_and_parts(local_did, Some(self.ident.name.clean(cx)), inner, cx)
@@ -1270,7 +1270,7 @@ impl Clean<Item> for ty::AssocItem {
12701270
let type_ = cx.tcx.type_of(self.def_id).clean(cx);
12711271
let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did));
12721272
TypedefItem(
1273-
Typedef {
1273+
box Typedef {
12741274
type_,
12751275
generics: Generics { params: Vec::new(), where_predicates: Vec::new() },
12761276
item_type,
@@ -1981,7 +1981,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
19811981
let rustdoc_ty = ty.clean(cx);
19821982
let item_type = rustdoc_ty.def_id().and_then(|did| inline::build_ty(cx, did));
19831983
TypedefItem(
1984-
Typedef { type_: rustdoc_ty, generics: generics.clean(cx), item_type },
1984+
box Typedef { type_: rustdoc_ty, generics: generics.clean(cx), item_type },
19851985
false,
19861986
)
19871987
}

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ crate enum ItemKind {
307307
EnumItem(Enum),
308308
FunctionItem(Box<Function>),
309309
ModuleItem(Module),
310-
TypedefItem(Typedef, bool /* is associated type */),
310+
TypedefItem(Box<Typedef>, bool /* is associated type */),
311311
OpaqueTyItem(OpaqueTy),
312312
StaticItem(Static),
313313
ConstantItem(Constant),

src/librustdoc/html/render/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3561,7 +3561,7 @@ fn render_deref_methods(
35613561
.items
35623562
.iter()
35633563
.find_map(|item| match item.kind {
3564-
clean::TypedefItem(ref t, true) => Some(match *t {
3564+
clean::TypedefItem(ref t, true) => Some(match **t {
35653565
clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_),
35663566
_ => (&t.type_, &t.type_),
35673567
}),
@@ -4239,7 +4239,7 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
42394239
{
42404240
if let Some((target, real_target)) =
42414241
impl_.inner_impl().items.iter().find_map(|item| match item.kind {
4242-
clean::TypedefItem(ref t, true) => Some(match *t {
4242+
clean::TypedefItem(ref t, true) => Some(match **t {
42434243
clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_),
42444244
_ => (&t.type_, &t.type_),
42454245
}),

src/librustdoc/json/conversions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl From<clean::ItemKind> for ItemEnum {
179179
StaticItem(s) => ItemEnum::StaticItem(s.into()),
180180
ForeignStaticItem(s) => ItemEnum::StaticItem(s.into()),
181181
ForeignTypeItem => ItemEnum::ForeignTypeItem,
182-
TypedefItem(t, _) => ItemEnum::TypedefItem(t.into()),
182+
TypedefItem(box t, _) => ItemEnum::TypedefItem(t.into()),
183183
OpaqueTyItem(t) => ItemEnum::OpaqueTyItem(t.into()),
184184
ConstantItem(c) => ItemEnum::ConstantItem(c.into()),
185185
MacroItem(m) => ItemEnum::MacroItem(m.source),

0 commit comments

Comments
 (0)