Skip to content

Commit 3657d09

Browse files
committedMay 21, 2022
Extend substs_to_args into a perfectly-sized Vec almost every time
1 parent 08237d8 commit 3657d09

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed
 

‎src/librustdoc/clean/utils.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,23 @@ pub(crate) fn substs_to_args(
8080
substs: &[ty::subst::GenericArg<'_>],
8181
mut skip_first: bool,
8282
) -> Vec<GenericArg> {
83-
substs
84-
.iter()
85-
.filter_map(|kind| match kind.unpack() {
86-
GenericArgKind::Lifetime(lt) => match *lt {
87-
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrAnon(_), .. }) => {
88-
Some(GenericArg::Lifetime(Lifetime::elided()))
89-
}
90-
_ => lt.clean(cx).map(GenericArg::Lifetime),
91-
},
92-
GenericArgKind::Type(_) if skip_first => {
93-
skip_first = false;
94-
None
83+
let mut ret_val =
84+
Vec::with_capacity(substs.len().saturating_sub(if skip_first { 1 } else { 0 }));
85+
ret_val.extend(substs.iter().filter_map(|kind| match kind.unpack() {
86+
GenericArgKind::Lifetime(lt) => match *lt {
87+
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrAnon(_), .. }) => {
88+
Some(GenericArg::Lifetime(Lifetime::elided()))
9589
}
96-
GenericArgKind::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
97-
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
98-
})
99-
.collect()
90+
_ => lt.clean(cx).map(GenericArg::Lifetime),
91+
},
92+
GenericArgKind::Type(_) if skip_first => {
93+
skip_first = false;
94+
None
95+
}
96+
GenericArgKind::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
97+
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
98+
}));
99+
ret_val
100100
}
101101

102102
fn external_generic_args(

0 commit comments

Comments
 (0)
Please sign in to comment.