Skip to content

Commit 7896b78

Browse files
committed
Box ItemKind::Impl to shrink the size of Item
1 parent 9684557 commit 7896b78

File tree

7 files changed

+10
-8
lines changed

7 files changed

+10
-8
lines changed

src/librustdoc/clean/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
126126
stability: None,
127127
const_stability: None,
128128
deprecation: None,
129-
kind: ImplItem(Impl {
129+
kind: ImplItem(box Impl {
130130
unsafety: hir::Unsafety::Normal,
131131
generics: new_generics,
132132
provided_trait_methods: Default::default(),

src/librustdoc/clean/blanket_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
115115
stability: None,
116116
const_stability: None,
117117
deprecation: None,
118-
kind: ImplItem(Impl {
118+
kind: ImplItem(box Impl {
119119
unsafety: hir::Unsafety::Normal,
120120
generics: (
121121
self.cx.tcx.generics_of(impl_def_id),

src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ crate fn build_impl(
438438
ret.push(clean::Item::from_def_id_and_parts(
439439
did,
440440
None,
441-
clean::ImplItem(clean::Impl {
441+
clean::ImplItem(box clean::Impl {
442442
unsafety: hir::Unsafety::Normal,
443443
generics,
444444
provided_trait_methods: provided,

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,7 @@ fn clean_impl(impl_: &hir::Item<'_>, cx: &DocContext<'_>) -> Vec<Item> {
20882088
_ => None,
20892089
});
20902090
let make_item = |trait_: Option<Type>, for_: Type, items: Vec<Item>| {
2091-
let kind = ImplItem(Impl {
2091+
let kind = ImplItem(box Impl {
20922092
unsafety,
20932093
generics: generics.clean(cx),
20942094
provided_trait_methods: provided.clone(),

src/librustdoc/clean/types.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ crate enum ItemKind {
313313
ConstantItem(Constant),
314314
TraitItem(Trait),
315315
TraitAliasItem(TraitAlias),
316-
ImplItem(Impl),
316+
// Impl is 400 bytes (!!), so box it to avoid penalizing other items
317+
// FIXME(jyn514): calculate this information on demand instead
318+
ImplItem(Box<Impl>),
317319
/// A method signature only. Used for required methods in traits (ie,
318320
/// non-default-methods).
319321
TyMethodItem(Function),

src/librustdoc/json/conversions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl From<clean::ItemKind> for ItemEnum {
175175
TraitAliasItem(t) => ItemEnum::TraitAliasItem(t.into()),
176176
MethodItem(m, _) => ItemEnum::MethodItem(m.into()),
177177
TyMethodItem(m) => ItemEnum::MethodItem(m.into()),
178-
ImplItem(i) => ItemEnum::ImplItem(i.into()),
178+
ImplItem(box i) => ItemEnum::ImplItem(i.into()),
179179
StaticItem(s) => ItemEnum::StaticItem(s.into()),
180180
ForeignStaticItem(s) => ItemEnum::StaticItem(s.into()),
181181
ForeignTypeItem => ItemEnum::ForeignTypeItem,

src/librustdoc/passes/collect_trait_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &DocContext<'_>) -> Crate {
5555

5656
// scan through included items ahead of time to splice in Deref targets to the "valid" sets
5757
for it in &new_items {
58-
if let ImplItem(Impl { ref for_, ref trait_, ref items, .. }) = it.kind {
58+
if let ImplItem(box Impl { ref for_, ref trait_, ref items, .. }) = it.kind {
5959
if cleaner.keep_item(for_) && trait_.def_id() == cx.tcx.lang_items().deref_trait() {
6060
let target = items
6161
.iter()
@@ -75,7 +75,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &DocContext<'_>) -> Crate {
7575
}
7676

7777
new_items.retain(|it| {
78-
if let ImplItem(Impl { ref for_, ref trait_, ref blanket_impl, .. }) = it.kind {
78+
if let ImplItem(box Impl { ref for_, ref trait_, ref blanket_impl, .. }) = it.kind {
7979
cleaner.keep_item(for_)
8080
|| trait_.as_ref().map_or(false, |t| cleaner.keep_item(t))
8181
|| blanket_impl.is_some()

0 commit comments

Comments
 (0)