Skip to content

Commit 1116fc1

Browse files
committed
Box FunctionItem, TyMethodItem, MethodItem, ForeignFunctionItem
This reduces ItemKind size from 160 bytes to 112 bytes
1 parent 96c051f commit 1116fc1

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

src/librustdoc/clean/inline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub(crate) fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean
218218
clean::Trait { def_id: did, generics, items: trait_items, bounds: supertrait_bounds }
219219
}
220220

221-
fn build_external_function<'tcx>(cx: &mut DocContext<'tcx>, did: DefId) -> clean::Function {
221+
fn build_external_function<'tcx>(cx: &mut DocContext<'tcx>, did: DefId) -> Box<clean::Function> {
222222
let sig = cx.tcx.fn_sig(did);
223223

224224
let predicates = cx.tcx.predicates_of(did);
@@ -228,7 +228,7 @@ fn build_external_function<'tcx>(cx: &mut DocContext<'tcx>, did: DefId) -> clean
228228
let decl = clean_fn_decl_from_did_and_sig(cx, Some(did), sig);
229229
(generics, decl)
230230
});
231-
clean::Function { decl, generics }
231+
Box::new(clean::Function { decl, generics })
232232
}
233233

234234
fn build_enum(cx: &mut DocContext<'_>, did: DefId) -> clean::Enum {

src/librustdoc/clean/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -908,15 +908,15 @@ fn clean_function<'tcx>(
908908
sig: &hir::FnSig<'tcx>,
909909
generics: &hir::Generics<'tcx>,
910910
body_id: hir::BodyId,
911-
) -> Function {
911+
) -> Box<Function> {
912912
let (generics, decl) = enter_impl_trait(cx, |cx| {
913913
// NOTE: generics must be cleaned before args
914914
let generics = generics.clean(cx);
915915
let args = clean_args_from_types_and_body_id(cx, sig.decl.inputs, body_id);
916916
let decl = clean_fn_decl_with_args(cx, sig.decl, args);
917917
(generics, decl)
918918
});
919-
Function { decl, generics }
919+
Box::new(Function { decl, generics })
920920
}
921921

922922
fn clean_args_from_types_and_names<'tcx>(
@@ -1061,7 +1061,7 @@ impl<'tcx> Clean<'tcx, Item> for hir::TraitItem<'tcx> {
10611061
let decl = clean_fn_decl_with_args(cx, sig.decl, args);
10621062
(generics, decl)
10631063
});
1064-
TyMethodItem(Function { decl, generics })
1064+
TyMethodItem(Box::new(Function { decl, generics }))
10651065
}
10661066
hir::TraitItemKind::Type(bounds, Some(default)) => {
10671067
let generics = enter_impl_trait(cx, |cx| self.generics.clean(cx));
@@ -1186,9 +1186,9 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem {
11861186
ty::ImplContainer(_) => Some(self.defaultness),
11871187
ty::TraitContainer(_) => None,
11881188
};
1189-
MethodItem(Function { generics, decl }, defaultness)
1189+
MethodItem(Box::new(Function { generics, decl }), defaultness)
11901190
} else {
1191-
TyMethodItem(Function { generics, decl })
1191+
TyMethodItem(Box::new(Function { generics, decl }))
11921192
}
11931193
}
11941194
ty::AssocKind::Type => {
@@ -2243,7 +2243,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
22432243
let decl = clean_fn_decl_with_args(cx, decl, args);
22442244
(generics, decl)
22452245
});
2246-
ForeignFunctionItem(Function { decl, generics })
2246+
ForeignFunctionItem(Box::new(Function { decl, generics }))
22472247
}
22482248
hir::ForeignItemKind::Static(ty, mutability) => {
22492249
ForeignStaticItem(Static { type_: clean_ty(ty, cx), mutability, expr: None })

src/librustdoc/clean/types.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ pub(crate) enum ItemKind {
730730
StructItem(Struct),
731731
UnionItem(Union),
732732
EnumItem(Enum),
733-
FunctionItem(Function),
733+
FunctionItem(Box<Function>),
734734
ModuleItem(Module),
735735
TypedefItem(Box<Typedef>),
736736
OpaqueTyItem(OpaqueTy),
@@ -740,15 +740,15 @@ pub(crate) enum ItemKind {
740740
TraitAliasItem(TraitAlias),
741741
ImplItem(Box<Impl>),
742742
/// A required method in a trait declaration meaning it's only a function signature.
743-
TyMethodItem(Function),
743+
TyMethodItem(Box<Function>),
744744
/// A method in a trait impl or a provided method in a trait declaration.
745745
///
746746
/// Compared to [TyMethodItem], it also contains a method body.
747-
MethodItem(Function, Option<hir::Defaultness>),
747+
MethodItem(Box<Function>, Option<hir::Defaultness>),
748748
StructFieldItem(Type),
749749
VariantItem(Variant),
750750
/// `fn`s from an extern block
751-
ForeignFunctionItem(Function),
751+
ForeignFunctionItem(Box<Function>),
752752
/// `static`s from an extern block
753753
ForeignStaticItem(Static),
754754
/// `type`s from an extern block

src/librustdoc/json/conversions.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,11 @@ impl FromWithTcx<Box<clean::Impl>> for Impl {
602602
}
603603

604604
pub(crate) fn from_function(
605-
function: clean::Function,
605+
function: Box<clean::Function>,
606606
header: rustc_hir::FnHeader,
607607
tcx: TyCtxt<'_>,
608608
) -> Function {
609-
let clean::Function { decl, generics } = function;
609+
let clean::Function { decl, generics } = *function;
610610
Function {
611611
decl: decl.into_tcx(tcx),
612612
generics: generics.into_tcx(tcx),
@@ -615,12 +615,12 @@ pub(crate) fn from_function(
615615
}
616616

617617
pub(crate) fn from_function_method(
618-
function: clean::Function,
618+
function: Box<clean::Function>,
619619
has_body: bool,
620620
header: rustc_hir::FnHeader,
621621
tcx: TyCtxt<'_>,
622622
) -> Method {
623-
let clean::Function { decl, generics } = function;
623+
let clean::Function { decl, generics } = *function;
624624
Method {
625625
decl: decl.into_tcx(tcx),
626626
generics: generics.into_tcx(tcx),

0 commit comments

Comments
 (0)