File tree 1 file changed +16
-9
lines changed
library/core/src/iter/traits
1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -3327,24 +3327,31 @@ pub trait Iterator {
3327
3327
///
3328
3328
/// [`is_sorted`]: Iterator::is_sorted
3329
3329
#[ unstable( feature = "is_sorted" , reason = "new API" , issue = "53485" ) ]
3330
- fn is_sorted_by < F > ( mut self , mut compare : F ) -> bool
3330
+ fn is_sorted_by < F > ( mut self , compare : F ) -> bool
3331
3331
where
3332
3332
Self : Sized ,
3333
3333
F : FnMut ( & Self :: Item , & Self :: Item ) -> Option < Ordering > ,
3334
3334
{
3335
+ #[ inline]
3336
+ fn check < ' a , T > (
3337
+ last : & ' a mut T ,
3338
+ mut compare : impl FnMut ( & T , & T ) -> Option < Ordering > + ' a ,
3339
+ ) -> impl FnMut ( T ) -> bool + ' a {
3340
+ move |curr| {
3341
+ if let Some ( Ordering :: Greater ) | None = compare ( & last, & curr) {
3342
+ return false ;
3343
+ }
3344
+ * last = curr;
3345
+ true
3346
+ }
3347
+ }
3348
+
3335
3349
let mut last = match self . next ( ) {
3336
3350
Some ( e) => e,
3337
3351
None => return true ,
3338
3352
} ;
3339
3353
3340
- while let Some ( curr) = self . next ( ) {
3341
- if let Some ( Ordering :: Greater ) | None = compare ( & last, & curr) {
3342
- return false ;
3343
- }
3344
- last = curr;
3345
- }
3346
-
3347
- true
3354
+ self . all ( check ( & mut last, compare) )
3348
3355
}
3349
3356
3350
3357
/// Checks if the elements of this iterator are sorted using the given key extraction
You can’t perform that action at this time.
0 commit comments