@@ -4,6 +4,7 @@ use super::super::{
4
4
Product , Rev , Scan , Skip , SkipWhile , StepBy , Sum , Take , TakeWhile , TrustedRandomAccessNoCoerce ,
5
5
Zip , try_process,
6
6
} ;
7
+ use super :: TrustedLen ;
7
8
use crate :: array;
8
9
use crate :: cmp:: { self , Ordering } ;
9
10
use crate :: num:: NonZero ;
@@ -3615,7 +3616,7 @@ pub trait Iterator {
3615
3616
}
3616
3617
}
3617
3618
3618
- match iter_compare ( self , other. into_iter ( ) , compare ( cmp) ) {
3619
+ match SpecIterCompare :: spec_iter_compare ( self , other. into_iter ( ) , compare ( cmp) ) {
3619
3620
ControlFlow :: Continue ( ord) => ord,
3620
3621
ControlFlow :: Break ( ord) => ord,
3621
3622
}
@@ -3707,7 +3708,7 @@ pub trait Iterator {
3707
3708
}
3708
3709
}
3709
3710
3710
- match iter_compare ( self , other. into_iter ( ) , compare ( partial_cmp) ) {
3711
+ match SpecIterCompare :: spec_iter_compare ( self , other. into_iter ( ) , compare ( partial_cmp) ) {
3711
3712
ControlFlow :: Continue ( ord) => Some ( ord) ,
3712
3713
ControlFlow :: Break ( ord) => ord,
3713
3714
}
@@ -3762,7 +3763,7 @@ pub trait Iterator {
3762
3763
}
3763
3764
}
3764
3765
3765
- match iter_compare ( self , other. into_iter ( ) , compare ( eq) ) {
3766
+ match SpecIterCompare :: spec_iter_compare ( self , other. into_iter ( ) , compare ( eq) ) {
3766
3767
ControlFlow :: Continue ( ord) => ord == Ordering :: Equal ,
3767
3768
ControlFlow :: Break ( ( ) ) => false ,
3768
3769
}
@@ -3984,6 +3985,41 @@ pub trait Iterator {
3984
3985
}
3985
3986
}
3986
3987
3988
+ trait SpecIterCompare < B : Iterator > : Iterator {
3989
+ fn spec_iter_compare < F , T > ( self , b : B , f : F ) -> ControlFlow < T , Ordering >
3990
+ where
3991
+ F : FnMut ( Self :: Item , B :: Item ) -> ControlFlow < T > ;
3992
+ }
3993
+
3994
+ impl < A : Iterator , B : Iterator > SpecIterCompare < B > for A {
3995
+ #[ inline]
3996
+ default fn spec_iter_compare < F , T > ( self , b : B , f : F ) -> ControlFlow < T , Ordering >
3997
+ where
3998
+ F : FnMut ( A :: Item , <B as Iterator >:: Item ) -> ControlFlow < T > ,
3999
+ {
4000
+ iter_compare ( self , b, f)
4001
+ }
4002
+ }
4003
+
4004
+ impl < A : Iterator + TrustedLen , B : Iterator + TrustedLen > SpecIterCompare < B > for A {
4005
+ #[ inline]
4006
+ fn spec_iter_compare < F , T > ( self , b : B , f : F ) -> ControlFlow < T , Ordering >
4007
+ where
4008
+ F : FnMut ( Self :: Item , <B as Iterator >:: Item ) -> ControlFlow < T > ,
4009
+ {
4010
+ if let ( _, Some ( a) ) = self . size_hint ( )
4011
+ && let ( _, Some ( b) ) = b. size_hint ( )
4012
+ {
4013
+ let ord = a. cmp ( & b) ;
4014
+ if ord != Ordering :: Equal {
4015
+ return ControlFlow :: Continue ( ord) ;
4016
+ }
4017
+ }
4018
+
4019
+ iter_compare ( self , b, f)
4020
+ }
4021
+ }
4022
+
3987
4023
/// Compares two iterators element-wise using the given function.
3988
4024
///
3989
4025
/// If `ControlFlow::Continue(())` is returned from the function, the comparison moves on to the next
0 commit comments