From eadb049799162fc5265f404bd4c6671d223e5dd2 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Sun, 23 Apr 2017 23:05:25 +0300 Subject: [PATCH] traits::select: quickly filter out predicates from other traits this improves most pre-trans passes's performance by ~1%. --- src/librustc/traits/select.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 6442487ead957..6dbf861d278d1 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -1300,8 +1300,13 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { .iter() .filter_map(|o| o.to_opt_poly_trait_ref()); + // micro-optimization: filter out predicates relating to different + // traits. 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()); let param_candidates =