Skip to content

Commit 9310aff

Browse files
committed
Auto merge of #80208 - bugadani:generics-of-alloc, r=matthewjasper
Reserve necessary space for params in generics_of Always reserve space for the exact number of generic parameters we need in generics_of. As far as I can see, the default is 0/4 elements based on has_self, and the vector grows on after that.
2 parents 11c94a1 + 01d7f87 commit 9310aff

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

compiler/rustc_typeck/src/collect.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,11 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
13691369
generics.parent_count + generics.params.len()
13701370
});
13711371

1372-
let mut params: Vec<_> = opt_self.into_iter().collect();
1372+
let mut params: Vec<_> = Vec::with_capacity(ast_generics.params.len() + has_self as usize);
1373+
1374+
if let Some(opt_self) = opt_self {
1375+
params.push(opt_self);
1376+
}
13731377

13741378
let early_lifetimes = early_bound_lifetimes_from_generics(tcx, ast_generics);
13751379
params.extend(early_lifetimes.enumerate().map(|(i, param)| ty::GenericParamDef {

0 commit comments

Comments
 (0)