Skip to content

Commit

Permalink
Box ItemKind::Impl to shrink the size of Item
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Dec 12, 2020
1 parent 9684557 commit 7896b78
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
stability: None,
const_stability: None,
deprecation: None,
kind: ImplItem(Impl {
kind: ImplItem(box Impl {
unsafety: hir::Unsafety::Normal,
generics: new_generics,
provided_trait_methods: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
stability: None,
const_stability: None,
deprecation: None,
kind: ImplItem(Impl {
kind: ImplItem(box Impl {
unsafety: hir::Unsafety::Normal,
generics: (
self.cx.tcx.generics_of(impl_def_id),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ crate fn build_impl(
ret.push(clean::Item::from_def_id_and_parts(
did,
None,
clean::ImplItem(clean::Impl {
clean::ImplItem(box clean::Impl {
unsafety: hir::Unsafety::Normal,
generics,
provided_trait_methods: provided,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ fn clean_impl(impl_: &hir::Item<'_>, cx: &DocContext<'_>) -> Vec<Item> {
_ => None,
});
let make_item = |trait_: Option<Type>, for_: Type, items: Vec<Item>| {
let kind = ImplItem(Impl {
let kind = ImplItem(box Impl {
unsafety,
generics: generics.clean(cx),
provided_trait_methods: provided.clone(),
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ crate enum ItemKind {
ConstantItem(Constant),
TraitItem(Trait),
TraitAliasItem(TraitAlias),
ImplItem(Impl),
// Impl is 400 bytes (!!), so box it to avoid penalizing other items
// FIXME(jyn514): calculate this information on demand instead
ImplItem(Box<Impl>),
/// A method signature only. Used for required methods in traits (ie,
/// non-default-methods).
TyMethodItem(Function),
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 @@ -175,7 +175,7 @@ impl From<clean::ItemKind> for ItemEnum {
TraitAliasItem(t) => ItemEnum::TraitAliasItem(t.into()),
MethodItem(m, _) => ItemEnum::MethodItem(m.into()),
TyMethodItem(m) => ItemEnum::MethodItem(m.into()),
ImplItem(i) => ItemEnum::ImplItem(i.into()),
ImplItem(box i) => ItemEnum::ImplItem(i.into()),
StaticItem(s) => ItemEnum::StaticItem(s.into()),
ForeignStaticItem(s) => ItemEnum::StaticItem(s.into()),
ForeignTypeItem => ItemEnum::ForeignTypeItem,
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/passes/collect_trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &DocContext<'_>) -> Crate {

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

new_items.retain(|it| {
if let ImplItem(Impl { ref for_, ref trait_, ref blanket_impl, .. }) = it.kind {
if let ImplItem(box Impl { ref for_, ref trait_, ref blanket_impl, .. }) = it.kind {
cleaner.keep_item(for_)
|| trait_.as_ref().map_or(false, |t| cleaner.keep_item(t))
|| blanket_impl.is_some()
Expand Down

0 comments on commit 7896b78

Please sign in to comment.