about summary refs log tree commit diff
path: root/src/libcore/iter
diff options
context:
space:
mode:
authorTim Vermeulen <tvermeulen@me.com>2019-03-12 20:24:10 +0100
committerTim Vermeulen <tvermeulen@me.com>2019-03-12 20:24:10 +0100
commit6cc5a3d9cc470e2db2b2a45fcddb2350ac0b039e (patch)
tree76d7ca0db4408db81f095bc511d1ed3944da5492 /src/libcore/iter
parent18192505568ce4c58995ca69652eaf088b17345b (diff)
downloadrust-6cc5a3d9cc470e2db2b2a45fcddb2350ac0b039e.tar.gz
rust-6cc5a3d9cc470e2db2b2a45fcddb2350ac0b039e.zip
Forward `max` and `min` to `max_by` and `min_by` respectively
Diffstat (limited to 'src/libcore/iter')
-rw-r--r--src/libcore/iter/traits/iterator.rs6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/libcore/iter/traits/iterator.rs b/src/libcore/iter/traits/iterator.rs
index 980de229fa6..ca7feed0712 100644
--- a/src/libcore/iter/traits/iterator.rs
+++ b/src/libcore/iter/traits/iterator.rs
@@ -2008,8 +2008,7 @@ pub trait Iterator {
     #[stable(feature = "rust1", since = "1.0.0")]
     fn max(self) -> Option<Self::Item> where Self: Sized, Self::Item: Ord
     {
-        // switch to y even if it is only equal, to preserve stability.
-        select_fold1(self, |x, y| x <= y)
+        self.max_by(Ord::cmp)
     }
 
     /// Returns the minimum element of an iterator.
@@ -2034,8 +2033,7 @@ pub trait Iterator {
     #[stable(feature = "rust1", since = "1.0.0")]
     fn min(self) -> Option<Self::Item> where Self: Sized, Self::Item: Ord
     {
-        // only switch to y if it is strictly smaller, to preserve stability.
-        select_fold1(self, |x, y| x > y)
+        self.min_by(Ord::cmp)
     }
 
     /// Returns the element that gives the maximum value from the