From b8893df8d344c11880c4aada639727fbfc195792 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 10 Feb 2020 14:28:56 +0100 Subject: [PATCH] preallocate 2 Vecs in traits; tweak WfPredicates::normalize --- src/librustc/traits/select.rs | 2 +- src/librustc/traits/wf.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 26f2a4ddb385a..ab47bf36b658d 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -3486,7 +3486,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // that order. let predicates = tcx.predicates_of(def_id); assert_eq!(predicates.parent, None); - let mut obligations = Vec::new(); + let mut obligations = Vec::with_capacity(predicates.predicates.len()); for (predicate, _) in predicates.predicates { let predicate = normalize_with_depth_to( self, diff --git a/src/librustc/traits/wf.rs b/src/librustc/traits/wf.rs index 1c47b5353160d..48721ec04e7fd 100644 --- a/src/librustc/traits/wf.rs +++ b/src/librustc/traits/wf.rs @@ -143,14 +143,15 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { let cause = self.cause(traits::MiscObligation); let infcx = &mut self.infcx; let param_env = self.param_env; - let mut obligations = Vec::new(); - self.out.iter().inspect(|pred| assert!(!pred.has_escaping_bound_vars())).for_each(|pred| { + let mut obligations = Vec::with_capacity(self.out.len()); + for pred in &self.out { + assert!(!pred.has_escaping_bound_vars()); let mut selcx = traits::SelectionContext::new(infcx); let i = obligations.len(); let value = traits::normalize_to(&mut selcx, param_env, cause.clone(), pred, &mut obligations); obligations.insert(i, value); - }); + } obligations }