From 446edd332885bf1a26259c220c7880aef59e1163 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Wed, 11 Nov 2009 13:05:05 +0000 Subject: fixed #2546 using patch from dlwh -- please rev... fixed #2546 using patch from dlwh -- please review! --- .../scala/collection/mutable/GenericArray.scala | 31 ++++++++++------------ .../scala/collection/mutable/ResizableArray.scala | 31 ++++++++++------------ 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/library/scala/collection/mutable/GenericArray.scala b/src/library/scala/collection/mutable/GenericArray.scala index 3af0ba8118..84341bacd4 100644 --- a/src/library/scala/collection/mutable/GenericArray.scala +++ b/src/library/scala/collection/mutable/GenericArray.scala @@ -41,23 +41,6 @@ extends IndexedSeq[A] array(idx) = elem.asInstanceOf[AnyRef] } - /** Fills the given array xs with the elements of - * this sequence starting at position start. - * - * @param xs the array to fill. - * @param start starting index. - */ - override def copyToArray[B >: A](xs: Array[B], start: Int) { - Array.copy(array, 0, xs, start, length) - } - - /** Copy all elements to a buffer - * @param The buffer to which elements are copied - override def copyToBuffer[B >: A](dest: Buffer[B]) { - dest ++= (array: Seq[AnyRef]).asInstanceOf[Seq[B]] - } - */ - override def foreach[U](f: A => U) { var i = 0 while (i < length) { @@ -65,6 +48,20 @@ extends IndexedSeq[A] i += 1 } } + + /** Fills the given array xs with at most `len` elements of + * this traversable starting at position `start`. + * Copying will stop once either the end of the current traversable is reached or + * `len` elements have been copied or the end of the array is reached. + * + * @param xs the array to fill. + * @param start starting index. + * @param len number of elements to copy + */ + override def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) { + val len1 = len min (xs.length - start) min length + Array.copy(array, 0, xs, start, len1) + } } object GenericArray extends SeqFactory[GenericArray] { diff --git a/src/library/scala/collection/mutable/ResizableArray.scala b/src/library/scala/collection/mutable/ResizableArray.scala index a433d4f7f0..a8fd82f726 100644 --- a/src/library/scala/collection/mutable/ResizableArray.scala +++ b/src/library/scala/collection/mutable/ResizableArray.scala @@ -50,23 +50,6 @@ trait ResizableArray[A] extends IndexedSeq[A] array(idx) = elem.asInstanceOf[AnyRef] } - /** Fills the given array xs with the elements of - * this sequence starting at position start. - * - * @param xs the array to fill. - * @param start starting index. - */ - override def copyToArray[B >: A](xs: Array[B], start: Int) { - Array.copy(array, 0, xs, start, size0) - } - - /** Copy all elements to a buffer - * @param The buffer to which elements are copied - override def copyToBuffer[B >: A](dest: Buffer[B]) { - dest ++= (array: Seq[AnyRef]).asInstanceOf[Seq[B]] - } - */ - override def foreach[U](f: A => U) { var i = 0 while (i < size) { @@ -75,6 +58,20 @@ trait ResizableArray[A] extends IndexedSeq[A] } } + /** Fills the given array xs with at most `len` elements of + * this traversable starting at position `start`. + * Copying will stop once either the end of the current traversable is reached or + * `len` elements have been copied or the end of the array is reached. + * + * @param xs the array to fill. + * @param start starting index. + * @param len number of elements to copy + */ + override def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) { + val len1 = len min (xs.length - start) min length + Array.copy(array, 0, xs, start, len1) + } + //########################################################################## /** remove elements of this array at indices after sz -- cgit v1.2.3