Skip to content

rustdoc: use ThinVec for generic arg parts #136265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
}
Expand Down Expand Up @@ -2202,8 +2201,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
alias_ty.map_bound(|ty| ty.args.as_slice()),
true,
def_id,
)
.into(),
),
constraints: Default::default(),
},
},
Expand Down Expand Up @@ -2521,7 +2519,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))),
Expand All @@ -2542,7 +2540,7 @@ fn clean_generic_args<'tcx>(
}
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
})
.collect::<Vec<_>>()
.collect::<ThinVec<_>>()
.into();
let constraints = generic_args
.constraints
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2254,8 +2254,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 {
Expand All @@ -2279,7 +2279,7 @@ impl GenericArgs {
assoc: PathSegment {
name: sym::Output,
args: GenericArgs::AngleBracketed {
args: Vec::new().into_boxed_slice(),
args: ThinVec::new(),
constraints: ThinVec::new(),
},
},
Expand Down Expand Up @@ -2596,12 +2596,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
}
6 changes: 3 additions & 3 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/search_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
})
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
},
}
Expand Down
Loading