Skip to content

Commit 4c8facf

Browse files
authored
Merge pull request scala/scala#7018 from lrytz/PQdeqA
PriorityQueue.dequeueAll returns an immutable.Seq
2 parents 18a5dc0 + eb0dbcc commit 4c8facf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

library/src/scala/collection/mutable/PriorityQueue.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import scala.math.Ordering
2929
* @example {{{
3030
* val pq = collection.mutable.PriorityQueue(1, 2, 5, 3, 7)
3131
* println(pq) // elements probably not in order
32-
* println(pq.clone.dequeueAll) // prints Vector(7, 5, 3, 2, 1)
32+
* println(pq.clone.dequeueAll) // prints ArraySeq(7, 5, 3, 2, 1)
3333
* }}}
3434
*
3535
* @tparam A type of the elements in this priority queue.
@@ -219,12 +219,13 @@ sealed class PriorityQueue[A](implicit val ord: Ordering[A])
219219
} else
220220
throw new NoSuchElementException("no element to remove from heap")
221221

222-
def dequeueAll[A1 >: A]: Seq[A1] = {
223-
val b = new ArrayBuffer[A1](size)
222+
def dequeueAll[A1 >: A]: immutable.Seq[A1] = {
223+
val b = ArrayBuilder.make[Any]
224+
b.sizeHint(size)
224225
while (nonEmpty) {
225226
b += dequeue()
226227
}
227-
b
228+
immutable.ArraySeq.unsafeWrapArray(b.result()).asInstanceOf[immutable.ArraySeq[A1]]
228229
}
229230

230231
/** Returns the element with the highest priority in the queue,

0 commit comments

Comments
 (0)