From 1116fc164f1fce1cab2753fab294bfe016457a69 Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 22 Jul 2022 00:11:21 +0200 Subject: [PATCH] Box FunctionItem, TyMethodItem, MethodItem, ForeignFunctionItem This reduces ItemKind size from 160 bytes to 112 bytes --- src/librustdoc/clean/inline.rs | 4 ++-- src/librustdoc/clean/mod.rs | 12 ++++++------ src/librustdoc/clean/types.rs | 8 ++++---- src/librustdoc/json/conversions.rs | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 6547c8944079..55d77a63f614 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -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 } } -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 { let sig = cx.tcx.fn_sig(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); (generics, decl) }); - clean::Function { decl, generics } + Box::new(clean::Function { decl, generics }) } fn build_enum(cx: &mut DocContext<'_>, did: DefId) -> clean::Enum { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index a216849083c8..10676aca480d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -908,7 +908,7 @@ fn clean_function<'tcx>( sig: &hir::FnSig<'tcx>, generics: &hir::Generics<'tcx>, body_id: hir::BodyId, -) -> Function { +) -> Box { let (generics, decl) = enter_impl_trait(cx, |cx| { // NOTE: generics must be cleaned before args let generics = generics.clean(cx); @@ -916,7 +916,7 @@ fn clean_function<'tcx>( let decl = clean_fn_decl_with_args(cx, sig.decl, args); (generics, decl) }); - Function { decl, generics } + Box::new(Function { decl, generics }) } 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); (generics, decl) }); - TyMethodItem(Function { decl, generics }) + TyMethodItem(Box::new(Function { decl, generics })) } hir::TraitItemKind::Type(bounds, Some(default)) => { 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::TraitContainer(_) => None, }; - MethodItem(Function { generics, decl }, defaultness) + MethodItem(Box::new(Function { generics, decl }), defaultness) } else { - TyMethodItem(Function { generics, decl }) + TyMethodItem(Box::new(Function { generics, decl })) } } ty::AssocKind::Type => { @@ -2243,7 +2243,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>( let decl = clean_fn_decl_with_args(cx, decl, args); (generics, decl) }); - ForeignFunctionItem(Function { decl, generics }) + ForeignFunctionItem(Box::new(Function { decl, generics })) } hir::ForeignItemKind::Static(ty, mutability) => { ForeignStaticItem(Static { type_: clean_ty(ty, cx), mutability, expr: None }) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index ced570c7f932..874cf5508d17 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -730,7 +730,7 @@ pub(crate) enum ItemKind { StructItem(Struct), UnionItem(Union), EnumItem(Enum), - FunctionItem(Function), + FunctionItem(Box), ModuleItem(Module), TypedefItem(Box), OpaqueTyItem(OpaqueTy), @@ -740,15 +740,15 @@ pub(crate) enum ItemKind { TraitAliasItem(TraitAlias), ImplItem(Box), /// A required method in a trait declaration meaning it's only a function signature. - TyMethodItem(Function), + TyMethodItem(Box), /// A method in a trait impl or a provided method in a trait declaration. /// /// Compared to [TyMethodItem], it also contains a method body. - MethodItem(Function, Option), + MethodItem(Box, Option), StructFieldItem(Type), VariantItem(Variant), /// `fn`s from an extern block - ForeignFunctionItem(Function), + ForeignFunctionItem(Box), /// `static`s from an extern block ForeignStaticItem(Static), /// `type`s from an extern block diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index b6ee385a833c..716a4c9ea431 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -602,11 +602,11 @@ impl FromWithTcx> for Impl { } pub(crate) fn from_function( - function: clean::Function, + function: Box, header: rustc_hir::FnHeader, tcx: TyCtxt<'_>, ) -> Function { - let clean::Function { decl, generics } = function; + let clean::Function { decl, generics } = *function; Function { decl: decl.into_tcx(tcx), generics: generics.into_tcx(tcx), @@ -615,12 +615,12 @@ pub(crate) fn from_function( } pub(crate) fn from_function_method( - function: clean::Function, + function: Box, has_body: bool, header: rustc_hir::FnHeader, tcx: TyCtxt<'_>, ) -> Method { - let clean::Function { decl, generics } = function; + let clean::Function { decl, generics } = *function; Method { decl: decl.into_tcx(tcx), generics: generics.into_tcx(tcx),