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.
This commit is contained in:
bors 2020-12-22 00:20:14 +00:00
commit 9310aff66c

View file

@ -1369,7 +1369,11 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
generics.parent_count + generics.params.len()
});
let mut params: Vec<_> = opt_self.into_iter().collect();
let mut params: Vec<_> = Vec::with_capacity(ast_generics.params.len() + has_self as usize);
if let Some(opt_self) = opt_self {
params.push(opt_self);
}
let early_lifetimes = early_bound_lifetimes_from_generics(tcx, ast_generics);
params.extend(early_lifetimes.enumerate().map(|(i, param)| ty::GenericParamDef {