Skip to content

Commit

Permalink
rustdoc: Box ty field of GenericParamDefKind::Const
Browse files Browse the repository at this point in the history
This cuts the size of `GenericParamDef` in half, from 104 bytes to 56
bytes. I think the extra indirection should be worth the size savings.
  • Loading branch information
camelid committed Oct 18, 2021
1 parent 9b52a63 commit 9098689
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -430,7 +430,7 @@ impl Clean<GenericParamDef> for ty::GenericParamDef {
self.name,
GenericParamDefKind::Const {
did: self.def_id,
ty: cx.tcx.type_of(self.def_id).clean(cx),
ty: Box::new(cx.tcx.type_of(self.def_id).clean(cx)),
default: match has_default {
true => Some(Box::new(cx.tcx.const_param_default(self.def_id).to_string())),
false => None,
Expand Down Expand Up @@ -470,7 +470,7 @@ impl Clean<GenericParamDef> for hir::GenericParam<'_> {
self.name.ident().name,
GenericParamDefKind::Const {
did: cx.tcx.hir().local_def_id(self.hir_id).to_def_id(),
ty: ty.clean(cx),
ty: Box::new(ty.clean(cx)),
default: default.map(|ct| {
let def_id = cx.tcx.hir().local_def_id(ct.hir_id);
Box::new(ty::Const::from_anon_const(cx.tcx, def_id).to_string())
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/clean/types.rs
Expand Up @@ -1224,7 +1224,7 @@ crate enum GenericParamDefKind {
},
Const {
did: DefId,
ty: Type,
ty: Box<Type>,
default: Option<Box<String>>,
},
}
Expand All @@ -1240,7 +1240,7 @@ impl GenericParamDefKind {
crate fn get_type(&self) -> Option<Type> {
match self {
GenericParamDefKind::Type { default, .. } => default.as_deref().cloned(),
GenericParamDefKind::Const { ty, .. } => Some(ty.clone()),
GenericParamDefKind::Const { ty, .. } => Some((&**ty).clone()),
GenericParamDefKind::Lifetime { .. } => None,
}
}
Expand All @@ -1254,7 +1254,7 @@ crate struct GenericParamDef {

// `GenericParamDef` is used in many places. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(GenericParamDef, 104);
rustc_data_structures::static_assert_size!(GenericParamDef, 56);

impl GenericParamDef {
crate fn is_synthetic_type_param(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/json/conversions.rs
Expand Up @@ -333,7 +333,7 @@ impl FromWithTcx<clean::GenericParamDefKind> for GenericParamDefKind {
default: default.map(|x| (*x).into_tcx(tcx)),
},
Const { did: _, ty, default } => {
GenericParamDefKind::Const { ty: ty.into_tcx(tcx), default: default.map(|x| *x) }
GenericParamDefKind::Const { ty: (*ty).into_tcx(tcx), default: default.map(|x| *x) }
}
}
}
Expand Down

0 comments on commit 9098689

Please sign in to comment.