about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2022-05-20 08:48:17 -0700
committerMichael Howell <michael@notriddle.com>2022-05-21 07:55:14 -0700
commit3657d0936f3b0e4f973d37ecb27dcd7ce91db4cc (patch)
tree9824e96d4522a00dacfb71a183340f4621a669a1
parent08237d8a6d60e9c11cef34ad1523821d28b6bd8e (diff)
downloadrust-3657d0936f3b0e4f973d37ecb27dcd7ce91db4cc.tar.gz
rust-3657d0936f3b0e4f973d37ecb27dcd7ce91db4cc.zip
Extend `substs_to_args` into a perfectly-sized Vec almost every time
-rw-r--r--src/librustdoc/clean/utils.rs32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs
index 4f8db980ad4..47597e0413a 100644
--- a/src/librustdoc/clean/utils.rs
+++ b/src/librustdoc/clean/utils.rs
@@ -80,23 +80,23 @@ pub(crate) fn substs_to_args(
     substs: &[ty::subst::GenericArg<'_>],
     mut skip_first: bool,
 ) -> Vec<GenericArg> {
-    substs
-        .iter()
-        .filter_map(|kind| match kind.unpack() {
-            GenericArgKind::Lifetime(lt) => match *lt {
-                ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrAnon(_), .. }) => {
-                    Some(GenericArg::Lifetime(Lifetime::elided()))
-                }
-                _ => lt.clean(cx).map(GenericArg::Lifetime),
-            },
-            GenericArgKind::Type(_) if skip_first => {
-                skip_first = false;
-                None
+    let mut ret_val =
+        Vec::with_capacity(substs.len().saturating_sub(if skip_first { 1 } else { 0 }));
+    ret_val.extend(substs.iter().filter_map(|kind| match kind.unpack() {
+        GenericArgKind::Lifetime(lt) => match *lt {
+            ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrAnon(_), .. }) => {
+                Some(GenericArg::Lifetime(Lifetime::elided()))
             }
-            GenericArgKind::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
-            GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
-        })
-        .collect()
+            _ => lt.clean(cx).map(GenericArg::Lifetime),
+        },
+        GenericArgKind::Type(_) if skip_first => {
+            skip_first = false;
+            None
+        }
+        GenericArgKind::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
+        GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
+    }));
+    ret_val
 }
 
 fn external_generic_args(