@@ -1551,31 +1551,36 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
15511551 where
15521552 T : IntoIterator < Item = ty:: Predicate < ' tcx > > + Clone ,
15531553 {
1554+ let cause = self . misc ( self . last_span ) ;
1555+ let obligations: Vec < _ > = predicates
1556+ . into_iter ( )
1557+ . map ( |p| traits:: Obligation :: new ( cause. clone ( ) , self . param_env , p) )
1558+ . collect ( ) ;
1559+
1560+ // Micro-optimization
1561+ if obligations. is_empty ( ) {
1562+ return ;
1563+ }
1564+
15541565 // This intermediate vector is mildly unfortunate, in that we
15551566 // sometimes create it even when logging is disabled, but only
15561567 // if debug-info is enabled, and I doubt it is actually
15571568 // expensive. -nmatsakis
15581569 let predicates_vec: Vec < _ > = if cfg ! ( debug_assertions) {
1559- predicates . clone ( ) . into_iter ( ) . collect ( )
1570+ obligations . iter ( ) . map ( |o| o . predicate ) . collect ( )
15601571 } else {
15611572 Vec :: new ( )
15621573 } ;
15631574
15641575 debug ! (
15651576 "prove_predicates(predicates={:?}, location={:?})" ,
1566- predicates_vec,
1567- location,
1577+ predicates_vec, location,
15681578 ) ;
15691579
15701580 self . fully_perform_op (
15711581 location. at_self ( ) ,
15721582 || format ! ( "prove_predicates({:?})" , predicates_vec) ,
1573- |this| {
1574- let cause = this. misc ( this. last_span ) ;
1575- let obligations = predicates
1576- . into_iter ( )
1577- . map ( |p| traits:: Obligation :: new ( cause. clone ( ) , this. param_env , p) )
1578- . collect ( ) ;
1583+ |_this| {
15791584 Ok ( InferOk {
15801585 value : ( ) ,
15811586 obligations,
@@ -1615,12 +1620,18 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
16151620 where
16161621 T : fmt:: Debug + TypeFoldable < ' tcx > ,
16171622 {
1623+ // Micro-optimization: avoid work when we don't have to
1624+ if !value. has_projections ( ) {
1625+ return value. clone ( ) ;
1626+ }
1627+
16181628 debug ! ( "normalize(value={:?}, location={:?})" , value, location) ;
16191629 self . fully_perform_op (
16201630 location. to_locations ( ) ,
16211631 || format ! ( "normalize(value={:?})" , value) ,
16221632 |this| {
1623- let Normalized { value, obligations } = this. infcx
1633+ let Normalized { value, obligations } = this
1634+ . infcx
16241635 . at ( & this. misc ( this. last_span ) , this. param_env )
16251636 . normalize ( value)
16261637 . unwrap_or_else ( |NoSolution | {
0 commit comments