Skip to content

Commit 3086510

Browse files
committed
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.
2 parents 6741521 + 3814ec5 commit 3086510

File tree

5 files changed

+15
-17
lines changed

5 files changed

+15
-17
lines changed

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

+4-6
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,7 @@ fn projection_to_path_segment<'tcx>(
516516
ty.map_bound(|ty| &ty.args[generics.parent_count..]),
517517
false,
518518
def_id,
519-
)
520-
.into(),
519+
),
521520
constraints: Default::default(),
522521
},
523522
}
@@ -2214,8 +2213,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
22142213
alias_ty.map_bound(|ty| ty.args.as_slice()),
22152214
true,
22162215
def_id,
2217-
)
2218-
.into(),
2216+
),
22192217
constraints: Default::default(),
22202218
},
22212219
},
@@ -2533,7 +2531,7 @@ fn clean_generic_args<'tcx>(
25332531
) -> GenericArgs {
25342532
// FIXME(return_type_notation): Fix RTN parens rendering
25352533
if let Some((inputs, output)) = generic_args.paren_sugar_inputs_output() {
2536-
let inputs = inputs.iter().map(|x| clean_ty(x, cx)).collect::<Vec<_>>().into();
2534+
let inputs = inputs.iter().map(|x| clean_ty(x, cx)).collect::<ThinVec<_>>().into();
25372535
let output = match output.kind {
25382536
hir::TyKind::Tup(&[]) => None,
25392537
_ => Some(Box::new(clean_ty(output, cx))),
@@ -2554,7 +2552,7 @@ fn clean_generic_args<'tcx>(
25542552
}
25552553
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
25562554
})
2557-
.collect::<Vec<_>>()
2555+
.collect::<ThinVec<_>>()
25582556
.into();
25592557
let constraints = generic_args
25602558
.constraints

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -2246,8 +2246,8 @@ impl GenericArg {
22462246

22472247
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
22482248
pub(crate) enum GenericArgs {
2249-
AngleBracketed { args: Box<[GenericArg]>, constraints: ThinVec<AssocItemConstraint> },
2250-
Parenthesized { inputs: Box<[Type]>, output: Option<Box<Type>> },
2249+
AngleBracketed { args: ThinVec<GenericArg>, constraints: ThinVec<AssocItemConstraint> },
2250+
Parenthesized { inputs: ThinVec<Type>, output: Option<Box<Type>> },
22512251
}
22522252

22532253
impl GenericArgs {
@@ -2271,7 +2271,7 @@ impl GenericArgs {
22712271
assoc: PathSegment {
22722272
name: sym::Output,
22732273
args: GenericArgs::AngleBracketed {
2274-
args: Vec::new().into_boxed_slice(),
2274+
args: ThinVec::new(),
22752275
constraints: ThinVec::new(),
22762276
},
22772277
},
@@ -2588,12 +2588,12 @@ mod size_asserts {
25882588
static_assert_size!(Crate, 56); // frequently moved by-value
25892589
static_assert_size!(DocFragment, 32);
25902590
static_assert_size!(GenericArg, 32);
2591-
static_assert_size!(GenericArgs, 32);
2591+
static_assert_size!(GenericArgs, 24);
25922592
static_assert_size!(GenericParamDef, 40);
25932593
static_assert_size!(Generics, 16);
25942594
static_assert_size!(Item, 48);
25952595
static_assert_size!(ItemKind, 48);
2596-
static_assert_size!(PathSegment, 40);
2596+
static_assert_size!(PathSegment, 32);
25972597
static_assert_size!(Type, 32);
25982598
// tidy-alphabetical-end
25992599
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
8181
args: ty::Binder<'tcx, &'tcx [ty::GenericArg<'tcx>]>,
8282
mut has_self: bool,
8383
owner: DefId,
84-
) -> Vec<GenericArg> {
84+
) -> ThinVec<GenericArg> {
8585
let (args, bound_vars) = (args.skip_binder(), args.bound_vars());
8686
if args.is_empty() {
8787
// Fast path which avoids executing the query `generics_of`.
88-
return Vec::new();
88+
return ThinVec::new();
8989
}
9090

9191
// 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>(
144144
};
145145

146146
let offset = if has_self { 1 } else { 0 };
147-
let mut clean_args = Vec::with_capacity(args.len().saturating_sub(offset));
147+
let mut clean_args = ThinVec::with_capacity(args.len().saturating_sub(offset));
148148
clean_args.extend(args.iter().enumerate().rev().filter_map(clean_arg));
149149
clean_args.reverse();
150150
clean_args

Diff for: src/librustdoc/html/render/search_index.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ pub(crate) fn get_function_type_for_search(
821821
.map(|name| clean::PathSegment {
822822
name: *name,
823823
args: clean::GenericArgs::AngleBracketed {
824-
args: Vec::new().into_boxed_slice(),
824+
args: ThinVec::new(),
825825
constraints: ThinVec::new(),
826826
},
827827
})

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,11 @@ impl FromClean<clean::GenericArgs> for GenericArgs {
231231
use clean::GenericArgs::*;
232232
match args {
233233
AngleBracketed { args, constraints } => GenericArgs::AngleBracketed {
234-
args: args.into_vec().into_json(renderer),
234+
args: args.into_json(renderer),
235235
constraints: constraints.into_json(renderer),
236236
},
237237
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
238-
inputs: inputs.into_vec().into_json(renderer),
238+
inputs: inputs.into_json(renderer),
239239
output: output.map(|a| (*a).into_json(renderer)),
240240
},
241241
}

0 commit comments

Comments
 (0)