summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/immutable/NumericRange.scala
diff options
context:
space:
mode:
authorTobias Schlatter <tobias@meisch.ch>2016-12-12 14:45:47 +0100
committerLukas Rytz <lukas.rytz@gmail.com>2016-12-12 14:45:47 +0100
commit738ac6d7d3902767cc4cd5820fe83632e558f049 (patch)
tree13bb9049714689485d486e6a31f9bd7db4bfd9b4 /src/library/scala/collection/immutable/NumericRange.scala
parent264cc5f20cd9a6b9c6d414dfea696de1b8608dc5 (diff)
downloadscala-738ac6d7d3902767cc4cd5820fe83632e558f049.tar.gz
scala-738ac6d7d3902767cc4cd5820fe83632e558f049.tar.bz2
scala-738ac6d7d3902767cc4cd5820fe83632e558f049.zip
SI-10086 NumericRange.min|max with custom Integral (#5575)
SI-10086 NumericRange.min|max with custom Integral
Diffstat (limited to 'src/library/scala/collection/immutable/NumericRange.scala')
-rw-r--r--src/library/scala/collection/immutable/NumericRange.scala9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/library/scala/collection/immutable/NumericRange.scala b/src/library/scala/collection/immutable/NumericRange.scala
index 11603a118b..59b8a40c64 100644
--- a/src/library/scala/collection/immutable/NumericRange.scala
+++ b/src/library/scala/collection/immutable/NumericRange.scala
@@ -116,13 +116,18 @@ extends AbstractSeq[T] with IndexedSeq[T] with Serializable {
import NumericRange.defaultOrdering
override def min[T1 >: T](implicit ord: Ordering[T1]): T =
- if (ord eq defaultOrdering(num)) {
+ // We can take the fast path:
+ // - If the Integral of this NumericRange is also the requested Ordering
+ // (Integral <: Ordering). This can happen for custom Integral types.
+ // - The Ordering is the default Ordering of a well-known Integral type.
+ if ((ord eq num) || defaultOrdering.get(num).exists(ord eq _)) {
if (num.signum(step) > 0) start
else last
} else super.min(ord)
override def max[T1 >: T](implicit ord: Ordering[T1]): T =
- if (ord eq defaultOrdering(num)) {
+ // See comment for fast path in min().
+ if ((ord eq num) || defaultOrdering.get(num).exists(ord eq _)) {
if (num.signum(step) > 0) last
else start
} else super.max(ord)