Box GenericArgs::Parenthesized.output
This reduces the size of `GenericArgs` from 104 bytes to 56 bytes, essentially reducing it by half. `GenericArgs` is one of the fields of `PathSegment`, so this should reduce the amount of memory allocated for `PathSegment`s in the cases where the generics are not for a `Fn`, `FnMut`, or `FnOnce` trait. I also added `static_assert_size!`s to `GenericArgs` and `PathSegment` to ensure they don't increase in size unexpectedly.
This commit is contained in:
parent
5d6804469d
commit
2d1240e6f7
5 changed files with 21 additions and 10 deletions
|
@ -350,8 +350,10 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|(ty, mut bounds)| {
|
.flat_map(|(ty, mut bounds)| {
|
||||||
if let Some(data) = ty_to_fn.get(&ty) {
|
if let Some(data) = ty_to_fn.get(&ty) {
|
||||||
let (poly_trait, output) =
|
let (poly_trait, output) = (
|
||||||
(data.0.as_ref().expect("as_ref failed").clone(), data.1.as_ref().cloned());
|
data.0.as_ref().expect("as_ref failed").clone(),
|
||||||
|
data.1.as_ref().cloned().map(Box::new),
|
||||||
|
);
|
||||||
let new_ty = match poly_trait.trait_ {
|
let new_ty = match poly_trait.trait_ {
|
||||||
Type::ResolvedPath { ref path, ref did, ref is_generic } => {
|
Type::ResolvedPath { ref path, ref did, ref is_generic } => {
|
||||||
let mut new_path = path.clone();
|
let mut new_path = path.clone();
|
||||||
|
|
|
@ -1763,10 +1763,9 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
|
||||||
fn clean(&self, cx: &mut DocContext<'_>) -> GenericArgs {
|
fn clean(&self, cx: &mut DocContext<'_>) -> GenericArgs {
|
||||||
if self.parenthesized {
|
if self.parenthesized {
|
||||||
let output = self.bindings[0].ty().clean(cx);
|
let output = self.bindings[0].ty().clean(cx);
|
||||||
GenericArgs::Parenthesized {
|
let output =
|
||||||
inputs: self.inputs().clean(cx),
|
if output != Type::Tuple(Vec::new()) { Some(Box::new(output)) } else { None };
|
||||||
output: if output != Type::Tuple(Vec::new()) { Some(output) } else { None },
|
GenericArgs::Parenthesized { inputs: self.inputs().clean(cx), output }
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
GenericArgs::AngleBracketed {
|
GenericArgs::AngleBracketed {
|
||||||
args: self
|
args: self
|
||||||
|
|
|
@ -116,10 +116,10 @@ crate fn merge_bounds(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
PP::Parenthesized { ref mut output, .. } => match output {
|
PP::Parenthesized { ref mut output, .. } => match output {
|
||||||
Some(o) => assert_eq!(o, rhs),
|
Some(o) => assert_eq!(o.as_ref(), rhs),
|
||||||
None => {
|
None => {
|
||||||
if *rhs != clean::Type::Tuple(Vec::new()) {
|
if *rhs != clean::Type::Tuple(Vec::new()) {
|
||||||
*output = Some(rhs.clone());
|
*output = Some(Box::new(rhs.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -2018,15 +2018,25 @@ crate enum GenericArg {
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||||
crate enum GenericArgs {
|
crate enum GenericArgs {
|
||||||
AngleBracketed { args: Vec<GenericArg>, bindings: Vec<TypeBinding> },
|
AngleBracketed { args: Vec<GenericArg>, bindings: Vec<TypeBinding> },
|
||||||
Parenthesized { inputs: Vec<Type>, output: Option<Type> },
|
Parenthesized { inputs: Vec<Type>, output: Option<Box<Type>> },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `GenericArgs` is in every `PathSegment`, so its size can significantly
|
||||||
|
// affect rustdoc's memory usage.
|
||||||
|
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||||
|
rustc_data_structures::static_assert_size!(GenericArgs, 56);
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||||
crate struct PathSegment {
|
crate struct PathSegment {
|
||||||
crate name: Symbol,
|
crate name: Symbol,
|
||||||
crate args: GenericArgs,
|
crate args: GenericArgs,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `PathSegment` usually occurs multiple times in every `Path`, so its size can
|
||||||
|
// significantly affect rustdoc's memory usage.
|
||||||
|
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||||
|
rustc_data_structures::static_assert_size!(PathSegment, 64);
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
crate struct Typedef {
|
crate struct Typedef {
|
||||||
crate type_: Type,
|
crate type_: Type,
|
||||||
|
|
|
@ -127,7 +127,7 @@ impl FromWithTcx<clean::GenericArgs> for GenericArgs {
|
||||||
},
|
},
|
||||||
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
|
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
|
||||||
inputs: inputs.into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
inputs: inputs.into_iter().map(|a| a.into_tcx(tcx)).collect(),
|
||||||
output: output.map(|a| a.into_tcx(tcx)),
|
output: output.map(|a| (*a).into_tcx(tcx)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue