Skip to content

Commit

Permalink
Rollup merge of rust-lang#69022 - ljedrz:traits_tweak_vecs, r=petroch…
Browse files Browse the repository at this point in the history
…enkov

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.
  • Loading branch information
Dylan-DPC authored Feb 11, 2020
2 parents c8c2b2b + b8893df commit d8b4abc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit d8b4abc

Please sign in to comment.