diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2009-11-11 13:05:05 +0000 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2009-11-11 13:05:05 +0000 |
commit | 446edd332885bf1a26259c220c7880aef59e1163 (patch) | |
tree | 5f33896f71ac544568e77b689384873ec50f96f7 /src | |
parent | fc07ece2e71a722dc44d366c8463dd27f825e289 (diff) | |
download | scala-446edd332885bf1a26259c220c7880aef59e1163.tar.gz scala-446edd332885bf1a26259c220c7880aef59e1163.tar.bz2 scala-446edd332885bf1a26259c220c7880aef59e1163.zip |
fixed #2546 using patch from dlwh -- please rev...
fixed #2546 using patch from dlwh -- please review!
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/mutable/GenericArray.scala | 31 | ||||
-rw-r--r-- | src/library/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 <code>xs</code> with the elements of - * this sequence starting at position <code>start</code>. - * - * @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 <code>xs</code> 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 <code>xs</code> with the elements of - * this sequence starting at position <code>start</code>. - * - * @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 <code>xs</code> 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 <code>sz</code> |