Skip to content

Commit 39e809d

Browse files
committed
Auto merge of #136265 - notriddle:notriddle/clean-up, r=<try>
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 ae5de6c + 3814ec5 commit 39e809d

File tree

5 files changed

+15
-17
lines changed

5 files changed

+15
-17
lines changed

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
}
@@ -2202,8 +2201,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
22022201
alias_ty.map_bound(|ty| ty.args.as_slice()),
22032202
true,
22042203
def_id,
2205-
)
2206-
.into(),
2204+
),
22072205
constraints: Default::default(),
22082206
},
22092207
},
@@ -2521,7 +2519,7 @@ fn clean_generic_args<'tcx>(
25212519
) -> GenericArgs {
25222520
// FIXME(return_type_notation): Fix RTN parens rendering
25232521
if let Some((inputs, output)) = generic_args.paren_sugar_inputs_output() {
2524-
let inputs = inputs.iter().map(|x| clean_ty(x, cx)).collect::<Vec<_>>().into();
2522+
let inputs = inputs.iter().map(|x| clean_ty(x, cx)).collect::<ThinVec<_>>().into();
25252523
let output = match output.kind {
25262524
hir::TyKind::Tup(&[]) => None,
25272525
_ => Some(Box::new(clean_ty(output, cx))),
@@ -2542,7 +2540,7 @@ fn clean_generic_args<'tcx>(
25422540
}
25432541
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
25442542
})
2545-
.collect::<Vec<_>>()
2543+
.collect::<ThinVec<_>>()
25462544
.into();
25472545
let constraints = generic_args
25482546
.constraints

src/librustdoc/clean/types.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2254,8 +2254,8 @@ impl GenericArg {
22542254

22552255
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
22562256
pub(crate) enum GenericArgs {
2257-
AngleBracketed { args: Box<[GenericArg]>, constraints: ThinVec<AssocItemConstraint> },
2258-
Parenthesized { inputs: Box<[Type]>, output: Option<Box<Type>> },
2257+
AngleBracketed { args: ThinVec<GenericArg>, constraints: ThinVec<AssocItemConstraint> },
2258+
Parenthesized { inputs: ThinVec<Type>, output: Option<Box<Type>> },
22592259
}
22602260

22612261
impl GenericArgs {
@@ -2279,7 +2279,7 @@ impl GenericArgs {
22792279
assoc: PathSegment {
22802280
name: sym::Output,
22812281
args: GenericArgs::AngleBracketed {
2282-
args: Vec::new().into_boxed_slice(),
2282+
args: ThinVec::new(),
22832283
constraints: ThinVec::new(),
22842284
},
22852285
},
@@ -2596,12 +2596,12 @@ mod size_asserts {
25962596
static_assert_size!(Crate, 56); // frequently moved by-value
25972597
static_assert_size!(DocFragment, 32);
25982598
static_assert_size!(GenericArg, 32);
2599-
static_assert_size!(GenericArgs, 32);
2599+
static_assert_size!(GenericArgs, 24);
26002600
static_assert_size!(GenericParamDef, 40);
26012601
static_assert_size!(Generics, 16);
26022602
static_assert_size!(Item, 48);
26032603
static_assert_size!(ItemKind, 48);
2604-
static_assert_size!(PathSegment, 40);
2604+
static_assert_size!(PathSegment, 32);
26052605
static_assert_size!(Type, 32);
26062606
// tidy-alphabetical-end
26072607
}

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

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
})

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)