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:
commit
30865107cb
5 changed files with 15 additions and 17 deletions
|
@ -516,8 +516,7 @@ fn projection_to_path_segment<'tcx>(
|
||||||
ty.map_bound(|ty| &ty.args[generics.parent_count..]),
|
ty.map_bound(|ty| &ty.args[generics.parent_count..]),
|
||||||
false,
|
false,
|
||||||
def_id,
|
def_id,
|
||||||
)
|
),
|
||||||
.into(),
|
|
||||||
constraints: Default::default(),
|
constraints: Default::default(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -2214,8 +2213,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
|
||||||
alias_ty.map_bound(|ty| ty.args.as_slice()),
|
alias_ty.map_bound(|ty| ty.args.as_slice()),
|
||||||
true,
|
true,
|
||||||
def_id,
|
def_id,
|
||||||
)
|
),
|
||||||
.into(),
|
|
||||||
constraints: Default::default(),
|
constraints: Default::default(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -2533,7 +2531,7 @@ fn clean_generic_args<'tcx>(
|
||||||
) -> GenericArgs {
|
) -> GenericArgs {
|
||||||
// FIXME(return_type_notation): Fix RTN parens rendering
|
// FIXME(return_type_notation): Fix RTN parens rendering
|
||||||
if let Some((inputs, output)) = generic_args.paren_sugar_inputs_output() {
|
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 {
|
let output = match output.kind {
|
||||||
hir::TyKind::Tup(&[]) => None,
|
hir::TyKind::Tup(&[]) => None,
|
||||||
_ => Some(Box::new(clean_ty(output, cx))),
|
_ => Some(Box::new(clean_ty(output, cx))),
|
||||||
|
@ -2554,7 +2552,7 @@ fn clean_generic_args<'tcx>(
|
||||||
}
|
}
|
||||||
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
|
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<ThinVec<_>>()
|
||||||
.into();
|
.into();
|
||||||
let constraints = generic_args
|
let constraints = generic_args
|
||||||
.constraints
|
.constraints
|
||||||
|
|
|
@ -2246,8 +2246,8 @@ impl GenericArg {
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||||
pub(crate) enum GenericArgs {
|
pub(crate) enum GenericArgs {
|
||||||
AngleBracketed { args: Box<[GenericArg]>, constraints: ThinVec<AssocItemConstraint> },
|
AngleBracketed { args: ThinVec<GenericArg>, constraints: ThinVec<AssocItemConstraint> },
|
||||||
Parenthesized { inputs: Box<[Type]>, output: Option<Box<Type>> },
|
Parenthesized { inputs: ThinVec<Type>, output: Option<Box<Type>> },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GenericArgs {
|
impl GenericArgs {
|
||||||
|
@ -2271,7 +2271,7 @@ impl GenericArgs {
|
||||||
assoc: PathSegment {
|
assoc: PathSegment {
|
||||||
name: sym::Output,
|
name: sym::Output,
|
||||||
args: GenericArgs::AngleBracketed {
|
args: GenericArgs::AngleBracketed {
|
||||||
args: Vec::new().into_boxed_slice(),
|
args: ThinVec::new(),
|
||||||
constraints: ThinVec::new(),
|
constraints: ThinVec::new(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -2588,12 +2588,12 @@ mod size_asserts {
|
||||||
static_assert_size!(Crate, 56); // frequently moved by-value
|
static_assert_size!(Crate, 56); // frequently moved by-value
|
||||||
static_assert_size!(DocFragment, 32);
|
static_assert_size!(DocFragment, 32);
|
||||||
static_assert_size!(GenericArg, 32);
|
static_assert_size!(GenericArg, 32);
|
||||||
static_assert_size!(GenericArgs, 32);
|
static_assert_size!(GenericArgs, 24);
|
||||||
static_assert_size!(GenericParamDef, 40);
|
static_assert_size!(GenericParamDef, 40);
|
||||||
static_assert_size!(Generics, 16);
|
static_assert_size!(Generics, 16);
|
||||||
static_assert_size!(Item, 48);
|
static_assert_size!(Item, 48);
|
||||||
static_assert_size!(ItemKind, 48);
|
static_assert_size!(ItemKind, 48);
|
||||||
static_assert_size!(PathSegment, 40);
|
static_assert_size!(PathSegment, 32);
|
||||||
static_assert_size!(Type, 32);
|
static_assert_size!(Type, 32);
|
||||||
// tidy-alphabetical-end
|
// tidy-alphabetical-end
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,11 +81,11 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
|
||||||
args: ty::Binder<'tcx, &'tcx [ty::GenericArg<'tcx>]>,
|
args: ty::Binder<'tcx, &'tcx [ty::GenericArg<'tcx>]>,
|
||||||
mut has_self: bool,
|
mut has_self: bool,
|
||||||
owner: DefId,
|
owner: DefId,
|
||||||
) -> Vec<GenericArg> {
|
) -> ThinVec<GenericArg> {
|
||||||
let (args, bound_vars) = (args.skip_binder(), args.bound_vars());
|
let (args, bound_vars) = (args.skip_binder(), args.bound_vars());
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
// Fast path which avoids executing the query `generics_of`.
|
// 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
|
// 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 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.extend(args.iter().enumerate().rev().filter_map(clean_arg));
|
||||||
clean_args.reverse();
|
clean_args.reverse();
|
||||||
clean_args
|
clean_args
|
||||||
|
|
|
@ -821,7 +821,7 @@ pub(crate) fn get_function_type_for_search(
|
||||||
.map(|name| clean::PathSegment {
|
.map(|name| clean::PathSegment {
|
||||||
name: *name,
|
name: *name,
|
||||||
args: clean::GenericArgs::AngleBracketed {
|
args: clean::GenericArgs::AngleBracketed {
|
||||||
args: Vec::new().into_boxed_slice(),
|
args: ThinVec::new(),
|
||||||
constraints: ThinVec::new(),
|
constraints: ThinVec::new(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -231,11 +231,11 @@ impl FromClean<clean::GenericArgs> for GenericArgs {
|
||||||
use clean::GenericArgs::*;
|
use clean::GenericArgs::*;
|
||||||
match args {
|
match args {
|
||||||
AngleBracketed { args, constraints } => GenericArgs::AngleBracketed {
|
AngleBracketed { args, constraints } => GenericArgs::AngleBracketed {
|
||||||
args: args.into_vec().into_json(renderer),
|
args: args.into_json(renderer),
|
||||||
constraints: constraints.into_json(renderer),
|
constraints: constraints.into_json(renderer),
|
||||||
},
|
},
|
||||||
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
|
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)),
|
output: output.map(|a| (*a).into_json(renderer)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue