Skip to content

Commit 9098689

Browse files
committed
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.
1 parent 9b52a63 commit 9098689

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Diff for: src/librustdoc/clean/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ impl Clean<GenericParamDef> for ty::GenericParamDef {
430430
self.name,
431431
GenericParamDefKind::Const {
432432
did: self.def_id,
433-
ty: cx.tcx.type_of(self.def_id).clean(cx),
433+
ty: Box::new(cx.tcx.type_of(self.def_id).clean(cx)),
434434
default: match has_default {
435435
true => Some(Box::new(cx.tcx.const_param_default(self.def_id).to_string())),
436436
false => None,
@@ -470,7 +470,7 @@ impl Clean<GenericParamDef> for hir::GenericParam<'_> {
470470
self.name.ident().name,
471471
GenericParamDefKind::Const {
472472
did: cx.tcx.hir().local_def_id(self.hir_id).to_def_id(),
473-
ty: ty.clean(cx),
473+
ty: Box::new(ty.clean(cx)),
474474
default: default.map(|ct| {
475475
let def_id = cx.tcx.hir().local_def_id(ct.hir_id);
476476
Box::new(ty::Const::from_anon_const(cx.tcx, def_id).to_string())

Diff for: src/librustdoc/clean/types.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ crate enum GenericParamDefKind {
12241224
},
12251225
Const {
12261226
did: DefId,
1227-
ty: Type,
1227+
ty: Box<Type>,
12281228
default: Option<Box<String>>,
12291229
},
12301230
}
@@ -1240,7 +1240,7 @@ impl GenericParamDefKind {
12401240
crate fn get_type(&self) -> Option<Type> {
12411241
match self {
12421242
GenericParamDefKind::Type { default, .. } => default.as_deref().cloned(),
1243-
GenericParamDefKind::Const { ty, .. } => Some(ty.clone()),
1243+
GenericParamDefKind::Const { ty, .. } => Some((&**ty).clone()),
12441244
GenericParamDefKind::Lifetime { .. } => None,
12451245
}
12461246
}
@@ -1254,7 +1254,7 @@ crate struct GenericParamDef {
12541254

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

12591259
impl GenericParamDef {
12601260
crate fn is_synthetic_type_param(&self) -> bool {

Diff for: src/librustdoc/json/conversions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl FromWithTcx<clean::GenericParamDefKind> for GenericParamDefKind {
333333
default: default.map(|x| (*x).into_tcx(tcx)),
334334
},
335335
Const { did: _, ty, default } => {
336-
GenericParamDefKind::Const { ty: ty.into_tcx(tcx), default: default.map(|x| *x) }
336+
GenericParamDefKind::Const { ty: (*ty).into_tcx(tcx), default: default.map(|x| *x) }
337337
}
338338
}
339339
}

0 commit comments

Comments
 (0)