diff options
| author | bors <bors@rust-lang.org> | 2021-09-02 00:12:21 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-09-02 00:12:21 +0000 |
| commit | e3c71f1e33b026dea7c9ca7c1c4554e63f56a0da (patch) | |
| tree | bef0127f5d8e5b5a78ed15be224ba9437c1e39e7 | |
| parent | 767edcf61630ee05a19e2be9085a153750b4d102 (diff) | |
| parent | 280e16787e6a9bd769754f29c37c045bc18016f4 (diff) | |
Auto merge of #88522 - camelid:box-paren-output, r=jyn514
rustdoc: Box `GenericArgs::Parenthesized.output` Split out from #88379. 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. r? `@jyn514`
| -rw-r--r-- | src/librustdoc/clean/auto_trait.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 7 | ||||
| -rw-r--r-- | src/librustdoc/clean/simplify.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/clean/types.rs | 12 | ||||
| -rw-r--r-- | src/librustdoc/json/conversions.rs | 2 |
5 files changed, 18 insertions, 9 deletions
diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 8ad09a9edc0..9217209fcf0 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -351,7 +351,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { .flat_map(|(ty, mut bounds)| { if let Some(data) = ty_to_fn.get(&ty) { let (poly_trait, output) = - (data.0.as_ref().expect("as_ref failed").clone(), data.1.as_ref().cloned()); + (data.0.as_ref().unwrap().clone(), data.1.as_ref().cloned().map(Box::new)); let new_ty = match poly_trait.trait_ { Type::ResolvedPath { ref path, ref did, ref is_generic } => { let mut new_path = path.clone(); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b566239423e..bde821c5d9c 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1773,10 +1773,9 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> { fn clean(&self, cx: &mut DocContext<'_>) -> GenericArgs { if self.parenthesized { let output = self.bindings[0].ty().clean(cx); - GenericArgs::Parenthesized { - inputs: self.inputs().clean(cx), - output: if output != Type::Tuple(Vec::new()) { Some(output) } else { None }, - } + let output = + if output != Type::Tuple(Vec::new()) { Some(Box::new(output)) } else { None }; + GenericArgs::Parenthesized { inputs: self.inputs().clean(cx), output } } else { GenericArgs::AngleBracketed { args: self diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index c0d52d34928..d139b19f5dc 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -116,10 +116,10 @@ crate fn merge_bounds( }); } PP::Parenthesized { ref mut output, .. } => match output { - Some(o) => assert_eq!(o, rhs), + Some(o) => assert_eq!(o.as_ref(), rhs), None => { if *rhs != clean::Type::Tuple(Vec::new()) { - *output = Some(rhs.clone()); + *output = Some(Box::new(rhs.clone())); } } }, diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 4194c99c0ba..36b862120a2 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -2019,15 +2019,25 @@ crate enum GenericArg { #[derive(Clone, PartialEq, Eq, Debug, Hash)] crate enum GenericArgs { 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)] crate struct PathSegment { crate name: Symbol, 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)] crate struct Typedef { crate type_: Type, diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 9453e6d35ee..228d718411f 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -127,7 +127,7 @@ impl FromWithTcx<clean::GenericArgs> for GenericArgs { }, Parenthesized { inputs, output } => GenericArgs::Parenthesized { 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)), }, } } |
