1
Fork 0

Shrink GenericArgs/PathSegment with boxed slices

This commit is contained in:
Michael Howell 2022-05-19 16:26:28 -07:00
parent 855e320fe2
commit 08237d8a6d
6 changed files with 20 additions and 19 deletions

View file

@ -544,7 +544,7 @@ fn build_module(
segments: vec![clean::PathSegment { segments: vec![clean::PathSegment {
name: prim_ty.as_sym(), name: prim_ty.as_sym(),
args: clean::GenericArgs::AngleBracketed { args: clean::GenericArgs::AngleBracketed {
args: Vec::new(), args: Default::default(),
bindings: ThinVec::new(), bindings: ThinVec::new(),
}, },
}], }],

View file

@ -420,7 +420,7 @@ fn projection_to_path_segment(ty: ty::ProjectionTy<'_>, cx: &mut DocContext<'_>)
PathSegment { PathSegment {
name: item.name, name: item.name,
args: GenericArgs::AngleBracketed { 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(), bindings: Default::default(),
}, },
} }
@ -1205,7 +1205,7 @@ impl Clean<Item> for ty::AssocItem {
|| generics || generics
.params .params
.iter() .iter()
.zip(args) .zip(&args[..])
.any(|(param, arg)| !param_eq_arg(param, arg)) .any(|(param, arg)| !param_eq_arg(param, arg))
{ {
return false; return false;
@ -1837,7 +1837,7 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
let output = self.bindings[0].ty().clean(cx); let output = self.bindings[0].ty().clean(cx);
let output = let output =
if output != Type::Tuple(Vec::new()) { Some(Box::new(output)) } else { None }; 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 } GenericArgs::Parenthesized { inputs, output }
} else { } else {
let args = self 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::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))),
hir::GenericArg::Infer(_inf) => GenericArg::Infer, hir::GenericArg::Infer(_inf) => GenericArg::Infer,
}) })
.collect(); .collect::<Vec<_>>()
let bindings = self.bindings.iter().map(|x| x.clean(cx)).collect(); .into();
let bindings = self.bindings.iter().map(|x| x.clean(cx)).collect::<Vec<_>>().into();
GenericArgs::AngleBracketed { args, bindings } GenericArgs::AngleBracketed { args, bindings }
} }
} }

View file

@ -2182,14 +2182,14 @@ rustc_data_structures::static_assert_size!(GenericArg, 80);
#[derive(Clone, PartialEq, Eq, Debug, Hash)] #[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(crate) enum GenericArgs { pub(crate) enum GenericArgs {
AngleBracketed { args: Vec<GenericArg>, bindings: ThinVec<TypeBinding> }, AngleBracketed { args: Box<[GenericArg]>, bindings: ThinVec<TypeBinding> },
Parenthesized { inputs: Vec<Type>, output: Option<Box<Type>> }, Parenthesized { inputs: Box<[Type]>, output: Option<Box<Type>> },
} }
// `GenericArgs` is in every `PathSegment`, so its size can significantly // `GenericArgs` is in every `PathSegment`, so its size can significantly
// affect rustdoc's memory usage. // affect rustdoc's memory usage.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] #[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)] #[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(crate) struct PathSegment { pub(crate) struct PathSegment {
@ -2200,7 +2200,7 @@ pub(crate) struct PathSegment {
// `PathSegment` usually occurs multiple times in every `Path`, so its size can // `PathSegment` usually occurs multiple times in every `Path`, so its size can
// significantly affect rustdoc's memory usage. // significantly affect rustdoc's memory usage.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] #[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)] #[derive(Clone, Debug)]
pub(crate) struct Typedef { pub(crate) struct Typedef {

View file

@ -112,8 +112,8 @@ fn external_generic_args(
let inputs = let inputs =
// The trait's first substitution is the one after self, if there is one. // 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() { 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(), ty::Tuple(tys) => tys.iter().map(|t| t.clean(cx)).collect::<Vec<_>>().into(),
_ => return GenericArgs::AngleBracketed { args, bindings: bindings.into() }, _ => return GenericArgs::AngleBracketed { args: args.into(), bindings: bindings.into() },
}; };
let output = None; let output = None;
// FIXME(#20299) return type comes from a projection now // FIXME(#20299) return type comes from a projection now
@ -123,7 +123,7 @@ fn external_generic_args(
// }; // };
GenericArgs::Parenthesized { inputs, output } GenericArgs::Parenthesized { inputs, output }
} else { } 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. /// Remove the generic arguments from a path.
pub(crate) fn strip_path_generics(mut path: Path) -> Path { pub(crate) fn strip_path_generics(mut path: Path) -> Path {
for ps in path.segments.iter_mut() { 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 path

View file

@ -457,7 +457,7 @@ impl clean::GenericArgs {
f.write_str("&lt;")?; f.write_str("&lt;")?;
} }
let mut comma = false; let mut comma = false;
for arg in args { for arg in &args[..] {
if comma { if comma {
f.write_str(", ")?; f.write_str(", ")?;
} }
@ -468,7 +468,7 @@ impl clean::GenericArgs {
write!(f, "{}", arg.print(cx))?; write!(f, "{}", arg.print(cx))?;
} }
} }
for binding in bindings { for binding in &bindings[..] {
if comma { if comma {
f.write_str(", ")?; f.write_str(", ")?;
} }
@ -489,7 +489,7 @@ impl clean::GenericArgs {
clean::GenericArgs::Parenthesized { inputs, output } => { clean::GenericArgs::Parenthesized { inputs, output } => {
f.write_str("(")?; f.write_str("(")?;
let mut comma = false; let mut comma = false;
for ty in inputs { for ty in &inputs[..] {
if comma { if comma {
f.write_str(", ")?; f.write_str(", ")?;
} }

View file

@ -119,11 +119,11 @@ impl FromWithTcx<clean::GenericArgs> for GenericArgs {
use clean::GenericArgs::*; use clean::GenericArgs::*;
match args { match args {
AngleBracketed { args, bindings } => GenericArgs::AngleBracketed { 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(), bindings: bindings.into_iter().map(|a| a.into_tcx(tcx)).collect(),
}, },
Parenthesized { inputs, output } => GenericArgs::Parenthesized { 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)), output: output.map(|a| (*a).into_tcx(tcx)),
}, },
} }