diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2016-05-05 23:09:13 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2016-05-05 23:09:13 +1000 |
commit | 2726320779356be1829aa1715888872606aa819b (patch) | |
tree | f0de3ac9511a4dd4c18ddc58ed1cce342dfa6e2e | |
parent | fbd2e35f7ceeab1dad04b55518b2c314e55a6851 (diff) | |
parent | 284571c74cac6c01dfa1c4af0d9d92f4f9fb04c0 (diff) | |
download | scala-2726320779356be1829aa1715888872606aa819b.tar.gz scala-2726320779356be1829aa1715888872606aa819b.tar.bz2 scala-2726320779356be1829aa1715888872606aa819b.zip |
Merge pull request #5132 from acdenhartog/patch-1
Avoid function chaining with reverse method
-rw-r--r-- | src/library/scala/collection/mutable/PriorityQueue.scala | 4 | ||||
-rw-r--r-- | test/junit/scala/collection/mutable/PriorityQueueTest.scala | 7 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/library/scala/collection/mutable/PriorityQueue.scala b/src/library/scala/collection/mutable/PriorityQueue.scala index b4112c03dd..d5b7673c37 100644 --- a/src/library/scala/collection/mutable/PriorityQueue.scala +++ b/src/library/scala/collection/mutable/PriorityQueue.scala @@ -200,9 +200,7 @@ sealed class PriorityQueue[A](implicit val ord: Ordering[A]) * @return A reversed priority queue. */ def reverse = { - val revq = new PriorityQueue[A]()(new scala.math.Ordering[A] { - def compare(x: A, y: A) = ord.compare(y, x) - }) + val revq = new PriorityQueue[A]()(ord.reverse) for (i <- 1 until resarr.length) revq += resarr(i) revq } diff --git a/test/junit/scala/collection/mutable/PriorityQueueTest.scala b/test/junit/scala/collection/mutable/PriorityQueueTest.scala index a14f1bf4c8..faedcf11f0 100644 --- a/test/junit/scala/collection/mutable/PriorityQueueTest.scala +++ b/test/junit/scala/collection/mutable/PriorityQueueTest.scala @@ -14,6 +14,12 @@ class PriorityQueueTest { priorityQueue.enqueue(elements :_*) @Test + def orderingReverseReverse() { + val pq = new mutable.PriorityQueue[Nothing]()((_,_)=>42) + assert(pq.ord eq pq.reverse.reverse.ord) + } + + @Test def canSerialize() { val outputStream = new ByteArrayOutputStream() new ObjectOutputStream(outputStream).writeObject(priorityQueue) @@ -27,6 +33,7 @@ class PriorityQueueTest { val objectInputStream = new ObjectInputStream(new ByteArrayInputStream(bytes)) val deserializedPriorityQueue = objectInputStream.readObject().asInstanceOf[PriorityQueue[Int]] + //correct sequencing is also tested here: assert(deserializedPriorityQueue.dequeueAll == elements.sorted.reverse) } } |