From c2a9a308cce58d1a1fec703235cdce4e7438e0a0 Mon Sep 17 00:00:00 2001 From: Tiark Rompf Date: Tue, 16 Mar 2010 23:06:10 +0000 Subject: closes #3112. no review. --- .../scala/collection/immutable/Vector.scala | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/library/scala/collection/immutable/Vector.scala') diff --git a/src/library/scala/collection/immutable/Vector.scala b/src/library/scala/collection/immutable/Vector.scala index 1326768090..6fb2aee054 100644 --- a/src/library/scala/collection/immutable/Vector.scala +++ b/src/library/scala/collection/immutable/Vector.scala @@ -108,34 +108,38 @@ override def companion: GenericCompanion[Vector] = Vector } override def take(n: Int): Vector[A] = { - if (n < 0) throw new IllegalArgumentException(n.toString) - if (startIndex + n < endIndex) { + if (n <= 0) + Vector.empty + else if (startIndex + n < endIndex) dropBack0(startIndex + n) - } else + else this } override def drop(n: Int): Vector[A] = { - if (n < 0) throw new IllegalArgumentException(n.toString) - if (startIndex + n < endIndex) { + if (n <= 0) + this + else if (startIndex + n < endIndex) dropFront0(startIndex + n) - } else + else Vector.empty } override def takeRight(n: Int): Vector[A] = { - if (n < 0) throw new IllegalArgumentException(n.toString) - if (endIndex - n > startIndex) { + if (n <= 0) + Vector.empty + else if (endIndex - n > startIndex) dropFront0(endIndex - n) - } else + else this } override def dropRight(n: Int): Vector[A] = { - if (n < 0) throw new IllegalArgumentException(n.toString) - if (endIndex - n > startIndex) { + if (n <= 0) + this + else if (endIndex - n > startIndex) dropBack0(endIndex - n) - } else + else Vector.empty } @@ -843,6 +847,7 @@ private[immutable] trait VectorPointer[T] { final def copyOf(a: Array[AnyRef]) = { //println("copy") + if (a eq null) println ("NULL") val b = new Array[AnyRef](a.length) Platform.arraycopy(a, 0, b, 0, a.length) b -- cgit v1.2.3