diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-02-11 16:36:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-11 16:36:59 +0100 |
| commit | d8b4abc4ad3fa2a230692844ccb499d8064f1ca4 (patch) | |
| tree | e44dd0ab08b515419fff8c3a48145d43bafc49ce | |
| parent | c8c2b2bc547f4fc0e36ced79cd7f64d514cc5329 (diff) | |
| parent | b8893df8d344c11880c4aada639727fbfc195792 (diff) | |
Rollup merge of #69022 - ljedrz:traits_tweak_vecs, r=petrochenkov
traits: preallocate 2 Vecs of known initial size The 2 preallocations are pretty obvious; both vectors will be as big as or larger than the collections they are created from. In `WfPredicates::normalize` the change from a functional style improves readability and should be perf-friendly, too.
| -rw-r--r-- | src/librustc/traits/select.rs | 2 | ||||
| -rw-r--r-- | 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 cfeb392f87f..17337ff0c92 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -3472,7 +3472,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 1c47b535316..48721ec04e7 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 } |
