traits::select: quickly filter out predicates from other traits

this improves most pre-trans passes's performance by ~1%.
This commit is contained in:
Ariel Ben-Yehuda 2017-04-23 23:05:25 +03:00
parent 23de823e93
commit eadb049799

View file

@ -1300,8 +1300,13 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
.iter() .iter()
.filter_map(|o| o.to_opt_poly_trait_ref()); .filter_map(|o| o.to_opt_poly_trait_ref());
// micro-optimization: filter out predicates relating to different
// traits.
let matching_bounds = let matching_bounds =
all_bounds.filter( all_bounds.filter(|p| p.def_id() == stack.obligation.predicate.def_id());
let matching_bounds =
matching_bounds.filter(
|bound| self.evaluate_where_clause(stack, bound.clone()).may_apply()); |bound| self.evaluate_where_clause(stack, bound.clone()).may_apply());
let param_candidates = let param_candidates =