rustdoc: Box ty field of GenericParamDefKind::Const
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.
This commit is contained in:
parent
9b52a633e4
commit
90986897c5
3 changed files with 6 additions and 6 deletions
|
|
@ -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,
|
||||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -1224,7 +1224,7 @@ crate enum GenericParamDefKind {
|
|||
},
|
||||
Const {
|
||||
did: DefId,
|
||||
ty: Type,
|
||||
ty: Box<Type>,
|
||||
default: Option<Box<String>>,
|
||||
},
|
||||
}
|
||||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue