1
Fork 0

Auto merge of #136265 - notriddle:notriddle/clean-up, r=fmease

rustdoc: use ThinVec for generic arg parts

This reduces the size of both these args, and of path segments, so should measurably help with memory use.
This commit is contained in:
bors 2025-02-06 00:53:53 +00:00
commit 30865107cb
5 changed files with 15 additions and 17 deletions

View file

@ -516,8 +516,7 @@ fn projection_to_path_segment<'tcx>(
ty.map_bound(|ty| &ty.args[generics.parent_count..]),
false,
def_id,
)
.into(),
),
constraints: Default::default(),
},
}
@ -2214,8 +2213,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
alias_ty.map_bound(|ty| ty.args.as_slice()),
true,
def_id,
)
.into(),
),
constraints: Default::default(),
},
},
@ -2533,7 +2531,7 @@ fn clean_generic_args<'tcx>(
) -> GenericArgs {
// FIXME(return_type_notation): Fix RTN parens rendering
if let Some((inputs, output)) = generic_args.paren_sugar_inputs_output() {
let inputs = inputs.iter().map(|x| clean_ty(x, cx)).collect::<Vec<_>>().into();
let inputs = inputs.iter().map(|x| clean_ty(x, cx)).collect::<ThinVec<_>>().into();
let output = match output.kind {
hir::TyKind::Tup(&[]) => None,
_ => Some(Box::new(clean_ty(output, cx))),
@ -2554,7 +2552,7 @@ fn clean_generic_args<'tcx>(
}
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
})
.collect::<Vec<_>>()
.collect::<ThinVec<_>>()
.into();
let constraints = generic_args
.constraints

View file

@ -2246,8 +2246,8 @@ impl GenericArg {
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(crate) enum GenericArgs {
AngleBracketed { args: Box<[GenericArg]>, constraints: ThinVec<AssocItemConstraint> },
Parenthesized { inputs: Box<[Type]>, output: Option<Box<Type>> },
AngleBracketed { args: ThinVec<GenericArg>, constraints: ThinVec<AssocItemConstraint> },
Parenthesized { inputs: ThinVec<Type>, output: Option<Box<Type>> },
}
impl GenericArgs {
@ -2271,7 +2271,7 @@ impl GenericArgs {
assoc: PathSegment {
name: sym::Output,
args: GenericArgs::AngleBracketed {
args: Vec::new().into_boxed_slice(),
args: ThinVec::new(),
constraints: ThinVec::new(),
},
},
@ -2588,12 +2588,12 @@ mod size_asserts {
static_assert_size!(Crate, 56); // frequently moved by-value
static_assert_size!(DocFragment, 32);
static_assert_size!(GenericArg, 32);
static_assert_size!(GenericArgs, 32);
static_assert_size!(GenericArgs, 24);
static_assert_size!(GenericParamDef, 40);
static_assert_size!(Generics, 16);
static_assert_size!(Item, 48);
static_assert_size!(ItemKind, 48);
static_assert_size!(PathSegment, 40);
static_assert_size!(PathSegment, 32);
static_assert_size!(Type, 32);
// tidy-alphabetical-end
}

View file

@ -81,11 +81,11 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
args: ty::Binder<'tcx, &'tcx [ty::GenericArg<'tcx>]>,
mut has_self: bool,
owner: DefId,
) -> Vec<GenericArg> {
) -> ThinVec<GenericArg> {
let (args, bound_vars) = (args.skip_binder(), args.bound_vars());
if args.is_empty() {
// Fast path which avoids executing the query `generics_of`.
return Vec::new();
return ThinVec::new();
}
// If the container is a trait object type, the arguments won't contain the self type but the
@ -144,7 +144,7 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
};
let offset = if has_self { 1 } else { 0 };
let mut clean_args = Vec::with_capacity(args.len().saturating_sub(offset));
let mut clean_args = ThinVec::with_capacity(args.len().saturating_sub(offset));
clean_args.extend(args.iter().enumerate().rev().filter_map(clean_arg));
clean_args.reverse();
clean_args

View file

@ -821,7 +821,7 @@ pub(crate) fn get_function_type_for_search(
.map(|name| clean::PathSegment {
name: *name,
args: clean::GenericArgs::AngleBracketed {
args: Vec::new().into_boxed_slice(),
args: ThinVec::new(),
constraints: ThinVec::new(),
},
})

View file

@ -231,11 +231,11 @@ impl FromClean<clean::GenericArgs> for GenericArgs {
use clean::GenericArgs::*;
match args {
AngleBracketed { args, constraints } => GenericArgs::AngleBracketed {
args: args.into_vec().into_json(renderer),
args: args.into_json(renderer),
constraints: constraints.into_json(renderer),
},
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
inputs: inputs.into_vec().into_json(renderer),
inputs: inputs.into_json(renderer),
output: output.map(|a| (*a).into_json(renderer)),
},
}