Skip to content

Commit

Permalink
preallocate 2 Vecs in traits; tweak WfPredicates::normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Feb 10, 2020
1 parent 840bdc3 commit b8893df
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 @@ -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,
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 b8893df

Please sign in to comment.