about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-02-06 00:53:53 +0000
committerbors <bors@rust-lang.org>2025-02-06 00:53:53 +0000
commit30865107cb8942ab8eaf9baf8d3aa2a6dec2643f (patch)
treec3c1df2220cd8bc860cc3b59e27f696becb6ea25 /src
parent6741521dc478182392806e816e919a36be5a2ba2 (diff)
parent3814ec5b16c3ad7f1a37099b3a89644defee4fdf (diff)
downloadrust-30865107cb8942ab8eaf9baf8d3aa2a6dec2643f.tar.gz
rust-30865107cb8942ab8eaf9baf8d3aa2a6dec2643f.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/clean/mod.rs10
-rw-r--r--src/librustdoc/clean/types.rs10
-rw-r--r--src/librustdoc/clean/utils.rs6
-rw-r--r--src/librustdoc/html/render/search_index.rs2
-rw-r--r--src/librustdoc/json/conversions.rs4
5 files changed, 15 insertions, 17 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 55bd7da8816..b14381c0c40 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -516,8 +516,7 @@ fn projection_to_path_segment<'tcx>(
                 ty.map_bound(|ty| &ty.args[generics.parent_count..]),
                 false,
                 def_id,
-            )
-            .into(),
+            ),
             constraints: Default::default(),
         },
     }
@@ -2214,8 +2213,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
                             alias_ty.map_bound(|ty| ty.args.as_slice()),
                             true,
                             def_id,
-                        )
-                        .into(),
+                        ),
                         constraints: Default::default(),
                     },
                 },
@@ -2533,7 +2531,7 @@ fn clean_generic_args<'tcx>(
 ) -> GenericArgs {
     // FIXME(return_type_notation): Fix RTN parens rendering
     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 {
             hir::TyKind::Tup(&[]) => None,
             _ => Some(Box::new(clean_ty(output, cx))),
@@ -2554,7 +2552,7 @@ fn clean_generic_args<'tcx>(
                 }
                 hir::GenericArg::Infer(_inf) => GenericArg::Infer,
             })
-            .collect::<Vec<_>>()
+            .collect::<ThinVec<_>>()
             .into();
         let constraints = generic_args
             .constraints
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index a44d74e6df6..583cd404dca 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -2246,8 +2246,8 @@ impl GenericArg {
 
 #[derive(Clone, PartialEq, Eq, Debug, Hash)]
 pub(crate) enum GenericArgs {
-    AngleBracketed { args: Box<[GenericArg]>, constraints: ThinVec<AssocItemConstraint> },
-    Parenthesized { inputs: Box<[Type]>, output: Option<Box<Type>> },
+    AngleBracketed { args: ThinVec<GenericArg>, constraints: ThinVec<AssocItemConstraint> },
+    Parenthesized { inputs: ThinVec<Type>, output: Option<Box<Type>> },
 }
 
 impl GenericArgs {
@@ -2271,7 +2271,7 @@ impl GenericArgs {
                         assoc: PathSegment {
                             name: sym::Output,
                             args: GenericArgs::AngleBracketed {
-                                args: Vec::new().into_boxed_slice(),
+                                args: ThinVec::new(),
                                 constraints: ThinVec::new(),
                             },
                         },
@@ -2588,12 +2588,12 @@ mod size_asserts {
     static_assert_size!(Crate, 56); // frequently moved by-value
     static_assert_size!(DocFragment, 32);
     static_assert_size!(GenericArg, 32);
-    static_assert_size!(GenericArgs, 32);
+    static_assert_size!(GenericArgs, 24);
     static_assert_size!(GenericParamDef, 40);
     static_assert_size!(Generics, 16);
     static_assert_size!(Item, 48);
     static_assert_size!(ItemKind, 48);
-    static_assert_size!(PathSegment, 40);
+    static_assert_size!(PathSegment, 32);
     static_assert_size!(Type, 32);
     // tidy-alphabetical-end
 }
diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs
index f1921b90cc6..8a7d140bb1a 100644
--- a/src/librustdoc/clean/utils.rs
+++ b/src/librustdoc/clean/utils.rs
@@ -81,11 +81,11 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
     args: ty::Binder<'tcx, &'tcx [ty::GenericArg<'tcx>]>,
     mut has_self: bool,
     owner: DefId,
-) -> Vec<GenericArg> {
+) -> ThinVec<GenericArg> {
     let (args, bound_vars) = (args.skip_binder(), args.bound_vars());
     if args.is_empty() {
         // 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
@@ -144,7 +144,7 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
     };
 
     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.reverse();
     clean_args
diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs
index e4a9a2b512e..8ac8b3a1f84 100644
--- a/src/librustdoc/html/render/search_index.rs
+++ b/src/librustdoc/html/render/search_index.rs
@@ -821,7 +821,7 @@ pub(crate) fn get_function_type_for_search(
                     .map(|name| clean::PathSegment {
                         name: *name,
                         args: clean::GenericArgs::AngleBracketed {
-                            args: Vec::new().into_boxed_slice(),
+                            args: ThinVec::new(),
                             constraints: ThinVec::new(),
                         },
                     })
diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs
index afe81937495..fcee2960979 100644
--- a/src/librustdoc/json/conversions.rs
+++ b/src/librustdoc/json/conversions.rs
@@ -231,11 +231,11 @@ impl FromClean<clean::GenericArgs> for GenericArgs {
         use clean::GenericArgs::*;
         match args {
             AngleBracketed { args, constraints } => GenericArgs::AngleBracketed {
-                args: args.into_vec().into_json(renderer),
+                args: args.into_json(renderer),
                 constraints: constraints.into_json(renderer),
             },
             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)),
             },
         }