summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-07-04 04:54:24 +0000
committerPaul Phillips <paulp@improving.org>2011-07-04 04:54:24 +0000
commit69b9d9858e6127d021e083d336e9629c12173698 (patch)
treec8151e479d91f238449e24c41d2f4edb807cb947
parentf34c836cb67ed4c03b03218dff0a048466cbf13f (diff)
downloadscala-69b9d9858e6127d021e083d336e9629c12173698.tar.gz
scala-69b9d9858e6127d021e083d336e9629c12173698.tar.bz2
scala-69b9d9858e6127d021e083d336e9629c12173698.zip
Hard to explain garbage led me to this innocent...
Hard to explain garbage led me to this innocent seeming change. Not that innocent. A function like this should create no garbage: final def f[T](xs: List[T], num: Int) { if (num > 0) f(Nil ::: xs ::: Nil, num - 1) } Instead it was creating a lot. No review.
-rw-r--r--src/library/scala/collection/immutable/List.scala1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala
index 5446b25888..563f14eac6 100644
--- a/src/library/scala/collection/immutable/List.scala
+++ b/src/library/scala/collection/immutable/List.scala
@@ -75,6 +75,7 @@ sealed abstract class List[+A] extends LinearSeq[A]
*/
def :::[B >: A](prefix: List[B]): List[B] =
if (isEmpty) prefix
+ else if (prefix.isEmpty) this
else (new ListBuffer[B] ++= prefix).prependToList(this)
/** Adds the elements of a given list in reverse order in front of this list.