Auto merge of #52438 - ljedrz:rustc_vec_capacity, r=eddyb

Calculate Vec capacities in librustc

Calculate the required capacity of a few vectors in rustc based on the number of elements they are populated with.
This commit is contained in:
bors 2018-07-21 00:55:46 +00:00
commit bf7afee52a
4 changed files with 48 additions and 58 deletions

View file

@ -565,7 +565,13 @@ impl<'a, 'tcx> FnTypeExt<'a, 'tcx> for FnType<'tcx, Ty<'tcx>> {
}
fn llvm_type(&self, cx: &CodegenCx<'a, 'tcx>) -> Type {
let mut llargument_tys = Vec::new();
let args_capacity: usize = self.args.iter().map(|arg|
if arg.pad.is_some() { 1 } else { 0 } +
if let PassMode::Pair(_, _) = arg.mode { 2 } else { 1 }
).sum();
let mut llargument_tys = Vec::with_capacity(
if let PassMode::Indirect(_) = self.ret.mode { 1 } else { 0 } + args_capacity
);
let llreturn_ty = match self.ret.mode {
PassMode::Ignore => Type::void(cx),