Shrink GenericArgs/PathSegment with boxed slices
This commit is contained in:
parent
855e320fe2
commit
08237d8a6d
@ -544,7 +544,7 @@ fn build_module(
|
||||
segments: vec![clean::PathSegment {
|
||||
name: prim_ty.as_sym(),
|
||||
args: clean::GenericArgs::AngleBracketed {
|
||||
args: Vec::new(),
|
||||
args: Default::default(),
|
||||
bindings: ThinVec::new(),
|
||||
},
|
||||
}],
|
||||
|
@ -420,7 +420,7 @@ fn projection_to_path_segment(ty: ty::ProjectionTy<'_>, cx: &mut DocContext<'_>)
|
||||
PathSegment {
|
||||
name: item.name,
|
||||
args: GenericArgs::AngleBracketed {
|
||||
args: substs_to_args(cx, &ty.substs[generics.parent_count..], false),
|
||||
args: substs_to_args(cx, &ty.substs[generics.parent_count..], false).into(),
|
||||
bindings: Default::default(),
|
||||
},
|
||||
}
|
||||
@ -1205,7 +1205,7 @@ impl Clean<Item> for ty::AssocItem {
|
||||
|| generics
|
||||
.params
|
||||
.iter()
|
||||
.zip(args)
|
||||
.zip(&args[..])
|
||||
.any(|(param, arg)| !param_eq_arg(param, arg))
|
||||
{
|
||||
return false;
|
||||
@ -1837,7 +1837,7 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
|
||||
let output = self.bindings[0].ty().clean(cx);
|
||||
let output =
|
||||
if output != Type::Tuple(Vec::new()) { Some(Box::new(output)) } else { None };
|
||||
let inputs = self.inputs().iter().map(|x| x.clean(cx)).collect();
|
||||
let inputs = self.inputs().iter().map(|x| x.clean(cx)).collect::<Vec<_>>().into();
|
||||
GenericArgs::Parenthesized { inputs, output }
|
||||
} else {
|
||||
let args = self
|
||||
@ -1852,8 +1852,9 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
|
||||
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))),
|
||||
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
|
||||
})
|
||||
.collect();
|
||||
let bindings = self.bindings.iter().map(|x| x.clean(cx)).collect();
|
||||
.collect::<Vec<_>>()
|
||||
.into();
|
||||
let bindings = self.bindings.iter().map(|x| x.clean(cx)).collect::<Vec<_>>().into();
|
||||
GenericArgs::AngleBracketed { args, bindings }
|
||||
}
|
||||
}
|
||||
|
@ -2182,14 +2182,14 @@ rustc_data_structures::static_assert_size!(GenericArg, 80);
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||
pub(crate) enum GenericArgs {
|
||||
AngleBracketed { args: Vec<GenericArg>, bindings: ThinVec<TypeBinding> },
|
||||
Parenthesized { inputs: Vec<Type>, output: Option<Box<Type>> },
|
||||
AngleBracketed { args: Box<[GenericArg]>, bindings: ThinVec<TypeBinding> },
|
||||
Parenthesized { inputs: Box<[Type]>, output: Option<Box<Type>> },
|
||||
}
|
||||
|
||||
// `GenericArgs` is in every `PathSegment`, so its size can significantly
|
||||
// affect rustdoc's memory usage.
|
||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||
rustc_data_structures::static_assert_size!(GenericArgs, 40);
|
||||
rustc_data_structures::static_assert_size!(GenericArgs, 32);
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||
pub(crate) struct PathSegment {
|
||||
@ -2200,7 +2200,7 @@ pub(crate) struct PathSegment {
|
||||
// `PathSegment` usually occurs multiple times in every `Path`, so its size can
|
||||
// significantly affect rustdoc's memory usage.
|
||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||
rustc_data_structures::static_assert_size!(PathSegment, 48);
|
||||
rustc_data_structures::static_assert_size!(PathSegment, 40);
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct Typedef {
|
||||
|
@ -112,8 +112,8 @@ fn external_generic_args(
|
||||
let inputs =
|
||||
// The trait's first substitution is the one after self, if there is one.
|
||||
match substs.iter().nth(if has_self { 1 } else { 0 }).unwrap().expect_ty().kind() {
|
||||
ty::Tuple(tys) => tys.iter().map(|t| t.clean(cx)).collect(),
|
||||
_ => return GenericArgs::AngleBracketed { args, bindings: bindings.into() },
|
||||
ty::Tuple(tys) => tys.iter().map(|t| t.clean(cx)).collect::<Vec<_>>().into(),
|
||||
_ => return GenericArgs::AngleBracketed { args: args.into(), bindings: bindings.into() },
|
||||
};
|
||||
let output = None;
|
||||
// FIXME(#20299) return type comes from a projection now
|
||||
@ -123,7 +123,7 @@ fn external_generic_args(
|
||||
// };
|
||||
GenericArgs::Parenthesized { inputs, output }
|
||||
} else {
|
||||
GenericArgs::AngleBracketed { args, bindings: bindings.into() }
|
||||
GenericArgs::AngleBracketed { args: args.into(), bindings: bindings.into() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ pub(super) fn external_path(
|
||||
/// Remove the generic arguments from a path.
|
||||
pub(crate) fn strip_path_generics(mut path: Path) -> Path {
|
||||
for ps in path.segments.iter_mut() {
|
||||
ps.args = GenericArgs::AngleBracketed { args: vec![], bindings: ThinVec::new() }
|
||||
ps.args = GenericArgs::AngleBracketed { args: Default::default(), bindings: ThinVec::new() }
|
||||
}
|
||||
|
||||
path
|
||||
|
@ -457,7 +457,7 @@ impl clean::GenericArgs {
|
||||
f.write_str("<")?;
|
||||
}
|
||||
let mut comma = false;
|
||||
for arg in args {
|
||||
for arg in &args[..] {
|
||||
if comma {
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
@ -468,7 +468,7 @@ impl clean::GenericArgs {
|
||||
write!(f, "{}", arg.print(cx))?;
|
||||
}
|
||||
}
|
||||
for binding in bindings {
|
||||
for binding in &bindings[..] {
|
||||
if comma {
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
@ -489,7 +489,7 @@ impl clean::GenericArgs {
|
||||
clean::GenericArgs::Parenthesized { inputs, output } => {
|
||||
f.write_str("(")?;
|
||||
let mut comma = false;
|
||||
for ty in inputs {
|
||||
for ty in &inputs[..] {
|
||||
if comma {
|
||||
f.write_str(", ")?;
|
||||
}
|
||||
|
@ -119,11 +119,11 @@ impl FromWithTcx<clean::GenericArgs> for GenericArgs {
|
||||
use clean::GenericArgs::*;
|
||||
match args {
|
||||
AngleBracketed { args, bindings } => GenericArgs::AngleBracketed {
|
||||
args: args.into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
||||
args: args.into_vec().into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
||||
bindings: bindings.into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
||||
},
|
||||
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
|
||||
inputs: inputs.into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
||||
inputs: inputs.into_vec().into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
||||
output: output.map(|a| (*a).into_tcx(tcx)),
|
||||
},
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user