diff options
author | Simon Ochsenreither <simon@ochsenreither.de> | 2013-12-10 00:47:59 +0100 |
---|---|---|
committer | Simon Ochsenreither <simon@ochsenreither.de> | 2013-12-11 21:50:09 +0100 |
commit | f0f0a5e7813501d985174d3c5573c34c8a7608c6 (patch) | |
tree | eb3d6cd0f03ef7c5c579a53c5f7445ba5b1b9c2c /src | |
parent | b345b42cac64aa97e3bbcc6f14ef8f08214ab56f (diff) | |
download | scala-f0f0a5e7813501d985174d3c5573c34c8a7608c6.tar.gz scala-f0f0a5e7813501d985174d3c5573c34c8a7608c6.tar.bz2 scala-f0f0a5e7813501d985174d3c5573c34c8a7608c6.zip |
SI-8059 Override immutable.Queue#{+:,:+} for performance
Without those overrides, all elements are unnecessarily copied.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/immutable/Queue.scala | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/library/scala/collection/immutable/Queue.scala b/src/library/scala/collection/immutable/Queue.scala index df1484c4ab..264304db68 100644 --- a/src/library/scala/collection/immutable/Queue.scala +++ b/src/library/scala/collection/immutable/Queue.scala @@ -89,6 +89,16 @@ class Queue[+A] protected(protected val in: List[A], protected val out: List[A]) */ override def length = in.length + out.length + override def +:[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Queue[A], B, That]): That = bf match { + case _: Queue.GenericCanBuildFrom[_] => new Queue(in, elem :: out).asInstanceOf[That] + case _ => super.+:(elem)(bf) + } + + override def :+[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Queue[A], B, That]): That = bf match { + case _: Queue.GenericCanBuildFrom[_] => enqueue(elem).asInstanceOf[That] + case _ => super.:+(elem)(bf) + } + /** Creates a new queue with element added at the end * of the old queue. * @@ -118,7 +128,7 @@ class Queue[+A] protected(protected val in: List[A], protected val out: List[A]) case x :: xs => (x, new Queue(in, xs)) case _ => throw new NoSuchElementException("dequeue on empty queue") } - + /** Optionally retrieves the first element and a queue of the remaining elements. * * @return A tuple of the first element of the queue, and a new queue with this element removed. |