diff options
author | Tobias Schlatter <tobias@meisch.ch> | 2016-12-12 14:45:47 +0100 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2016-12-12 14:45:47 +0100 |
commit | 738ac6d7d3902767cc4cd5820fe83632e558f049 (patch) | |
tree | 13bb9049714689485d486e6a31f9bd7db4bfd9b4 /src | |
parent | 264cc5f20cd9a6b9c6d414dfea696de1b8608dc5 (diff) | |
download | scala-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')
-rw-r--r-- | src/library/scala/collection/immutable/NumericRange.scala | 9 |
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) |