summaryrefslogtreecommitdiff
path: root/src/library/scala/collection
diff options
context:
space:
mode:
authorEdmund Noble <edmundnoble@gmail.com>2016-12-04 20:15:30 -0500
committerEdmund Noble <Edmund Noble>2017-01-18 17:36:45 -0500
commit409f84d29f1dfae112a024d90aeb187248d48a3c (patch)
tree800936ed6f1a34ac1607cb5e2d6ca0a6a7679684 /src/library/scala/collection
parent264cc5f20cd9a6b9c6d414dfea696de1b8608dc5 (diff)
downloadscala-409f84d29f1dfae112a024d90aeb187248d48a3c.tar.gz
scala-409f84d29f1dfae112a024d90aeb187248d48a3c.tar.bz2
scala-409f84d29f1dfae112a024d90aeb187248d48a3c.zip
Improve Queue.++ when building another Queue
Use reverse_:::
Diffstat (limited to 'src/library/scala/collection')
-rw-r--r--src/library/scala/collection/immutable/Queue.scala9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/library/scala/collection/immutable/Queue.scala b/src/library/scala/collection/immutable/Queue.scala
index 53af3ce158..bb029ebe70 100644
--- a/src/library/scala/collection/immutable/Queue.scala
+++ b/src/library/scala/collection/immutable/Queue.scala
@@ -100,6 +100,15 @@ class Queue[+A] protected(protected val in: List[A], protected val out: List[A])
case _ => super.:+(elem)(bf)
}
+ override def ++[B >: A, That](that: GenTraversableOnce[B])(implicit bf: CanBuildFrom[Queue[A], B, That]): That = {
+ if (bf eq Queue.ReusableCBF) {
+ val thatQueue = that.asInstanceOf[Queue[B]]
+ new Queue[B](thatQueue.in ++ (thatQueue.out reverse_::: this.in), this.out).asInstanceOf[That]
+ } else {
+ super.++(that)(bf)
+ }
+ }
+
/** Creates a new queue with element added at the end
* of the old queue.
*