1
Fork 0

Box FunctionItem, TyMethodItem, MethodItem, ForeignFunctionItem

This reduces ItemKind size from 160 bytes to 112 bytes
This commit is contained in:
est31 2022-07-22 00:11:21 +02:00
parent 96c051fd07
commit 1116fc164f
4 changed files with 16 additions and 16 deletions

View file

@ -218,7 +218,7 @@ pub(crate) fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean
clean::Trait { def_id: did, generics, items: trait_items, bounds: supertrait_bounds } clean::Trait { def_id: did, generics, items: trait_items, bounds: supertrait_bounds }
} }
fn build_external_function<'tcx>(cx: &mut DocContext<'tcx>, did: DefId) -> clean::Function { fn build_external_function<'tcx>(cx: &mut DocContext<'tcx>, did: DefId) -> Box<clean::Function> {
let sig = cx.tcx.fn_sig(did); let sig = cx.tcx.fn_sig(did);
let predicates = cx.tcx.predicates_of(did); let predicates = cx.tcx.predicates_of(did);
@ -228,7 +228,7 @@ fn build_external_function<'tcx>(cx: &mut DocContext<'tcx>, did: DefId) -> clean
let decl = clean_fn_decl_from_did_and_sig(cx, Some(did), sig); let decl = clean_fn_decl_from_did_and_sig(cx, Some(did), sig);
(generics, decl) (generics, decl)
}); });
clean::Function { decl, generics } Box::new(clean::Function { decl, generics })
} }
fn build_enum(cx: &mut DocContext<'_>, did: DefId) -> clean::Enum { fn build_enum(cx: &mut DocContext<'_>, did: DefId) -> clean::Enum {

View file

@ -908,7 +908,7 @@ fn clean_function<'tcx>(
sig: &hir::FnSig<'tcx>, sig: &hir::FnSig<'tcx>,
generics: &hir::Generics<'tcx>, generics: &hir::Generics<'tcx>,
body_id: hir::BodyId, body_id: hir::BodyId,
) -> Function { ) -> Box<Function> {
let (generics, decl) = enter_impl_trait(cx, |cx| { let (generics, decl) = enter_impl_trait(cx, |cx| {
// NOTE: generics must be cleaned before args // NOTE: generics must be cleaned before args
let generics = generics.clean(cx); let generics = generics.clean(cx);
@ -916,7 +916,7 @@ fn clean_function<'tcx>(
let decl = clean_fn_decl_with_args(cx, sig.decl, args); let decl = clean_fn_decl_with_args(cx, sig.decl, args);
(generics, decl) (generics, decl)
}); });
Function { decl, generics } Box::new(Function { decl, generics })
} }
fn clean_args_from_types_and_names<'tcx>( fn clean_args_from_types_and_names<'tcx>(
@ -1061,7 +1061,7 @@ impl<'tcx> Clean<'tcx, Item> for hir::TraitItem<'tcx> {
let decl = clean_fn_decl_with_args(cx, sig.decl, args); let decl = clean_fn_decl_with_args(cx, sig.decl, args);
(generics, decl) (generics, decl)
}); });
TyMethodItem(Function { decl, generics }) TyMethodItem(Box::new(Function { decl, generics }))
} }
hir::TraitItemKind::Type(bounds, Some(default)) => { hir::TraitItemKind::Type(bounds, Some(default)) => {
let generics = enter_impl_trait(cx, |cx| self.generics.clean(cx)); let generics = enter_impl_trait(cx, |cx| self.generics.clean(cx));
@ -1186,9 +1186,9 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem {
ty::ImplContainer(_) => Some(self.defaultness), ty::ImplContainer(_) => Some(self.defaultness),
ty::TraitContainer(_) => None, ty::TraitContainer(_) => None,
}; };
MethodItem(Function { generics, decl }, defaultness) MethodItem(Box::new(Function { generics, decl }), defaultness)
} else { } else {
TyMethodItem(Function { generics, decl }) TyMethodItem(Box::new(Function { generics, decl }))
} }
} }
ty::AssocKind::Type => { ty::AssocKind::Type => {
@ -2243,7 +2243,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
let decl = clean_fn_decl_with_args(cx, decl, args); let decl = clean_fn_decl_with_args(cx, decl, args);
(generics, decl) (generics, decl)
}); });
ForeignFunctionItem(Function { decl, generics }) ForeignFunctionItem(Box::new(Function { decl, generics }))
} }
hir::ForeignItemKind::Static(ty, mutability) => { hir::ForeignItemKind::Static(ty, mutability) => {
ForeignStaticItem(Static { type_: clean_ty(ty, cx), mutability, expr: None }) ForeignStaticItem(Static { type_: clean_ty(ty, cx), mutability, expr: None })

View file

@ -730,7 +730,7 @@ pub(crate) enum ItemKind {
StructItem(Struct), StructItem(Struct),
UnionItem(Union), UnionItem(Union),
EnumItem(Enum), EnumItem(Enum),
FunctionItem(Function), FunctionItem(Box<Function>),
ModuleItem(Module), ModuleItem(Module),
TypedefItem(Box<Typedef>), TypedefItem(Box<Typedef>),
OpaqueTyItem(OpaqueTy), OpaqueTyItem(OpaqueTy),
@ -740,15 +740,15 @@ pub(crate) enum ItemKind {
TraitAliasItem(TraitAlias), TraitAliasItem(TraitAlias),
ImplItem(Box<Impl>), ImplItem(Box<Impl>),
/// A required method in a trait declaration meaning it's only a function signature. /// A required method in a trait declaration meaning it's only a function signature.
TyMethodItem(Function), TyMethodItem(Box<Function>),
/// A method in a trait impl or a provided method in a trait declaration. /// A method in a trait impl or a provided method in a trait declaration.
/// ///
/// Compared to [TyMethodItem], it also contains a method body. /// Compared to [TyMethodItem], it also contains a method body.
MethodItem(Function, Option<hir::Defaultness>), MethodItem(Box<Function>, Option<hir::Defaultness>),
StructFieldItem(Type), StructFieldItem(Type),
VariantItem(Variant), VariantItem(Variant),
/// `fn`s from an extern block /// `fn`s from an extern block
ForeignFunctionItem(Function), ForeignFunctionItem(Box<Function>),
/// `static`s from an extern block /// `static`s from an extern block
ForeignStaticItem(Static), ForeignStaticItem(Static),
/// `type`s from an extern block /// `type`s from an extern block

View file

@ -602,11 +602,11 @@ impl FromWithTcx<Box<clean::Impl>> for Impl {
} }
pub(crate) fn from_function( pub(crate) fn from_function(
function: clean::Function, function: Box<clean::Function>,
header: rustc_hir::FnHeader, header: rustc_hir::FnHeader,
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
) -> Function { ) -> Function {
let clean::Function { decl, generics } = function; let clean::Function { decl, generics } = *function;
Function { Function {
decl: decl.into_tcx(tcx), decl: decl.into_tcx(tcx),
generics: generics.into_tcx(tcx), generics: generics.into_tcx(tcx),
@ -615,12 +615,12 @@ pub(crate) fn from_function(
} }
pub(crate) fn from_function_method( pub(crate) fn from_function_method(
function: clean::Function, function: Box<clean::Function>,
has_body: bool, has_body: bool,
header: rustc_hir::FnHeader, header: rustc_hir::FnHeader,
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
) -> Method { ) -> Method {
let clean::Function { decl, generics } = function; let clean::Function { decl, generics } = *function;
Method { Method {
decl: decl.into_tcx(tcx), decl: decl.into_tcx(tcx),
generics: generics.into_tcx(tcx), generics: generics.into_tcx(tcx),