Skip to content

Commit 446edd3

Browse files
author
Adriaan Moors
committed
fixed scala#2546 using patch from dlwh -- please rev...
fixed scala#2546 using patch from dlwh -- please review!
1 parent fc07ece commit 446edd3

File tree

2 files changed

+28
-34
lines changed

2 files changed

+28
-34
lines changed

src/library/scala/collection/mutable/GenericArray.scala

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,27 @@ extends IndexedSeq[A]
4141
array(idx) = elem.asInstanceOf[AnyRef]
4242
}
4343

44-
/** Fills the given array <code>xs</code> with the elements of
45-
* this sequence starting at position <code>start</code>.
46-
*
47-
* @param xs the array to fill.
48-
* @param start starting index.
49-
*/
50-
override def copyToArray[B >: A](xs: Array[B], start: Int) {
51-
Array.copy(array, 0, xs, start, length)
52-
}
53-
54-
/** Copy all elements to a buffer
55-
* @param The buffer to which elements are copied
56-
override def copyToBuffer[B >: A](dest: Buffer[B]) {
57-
dest ++= (array: Seq[AnyRef]).asInstanceOf[Seq[B]]
58-
}
59-
*/
60-
6144
override def foreach[U](f: A => U) {
6245
var i = 0
6346
while (i < length) {
6447
f(array(i).asInstanceOf[A])
6548
i += 1
6649
}
6750
}
51+
52+
/** Fills the given array <code>xs</code> with at most `len` elements of
53+
* this traversable starting at position `start`.
54+
* Copying will stop once either the end of the current traversable is reached or
55+
* `len` elements have been copied or the end of the array is reached.
56+
*
57+
* @param xs the array to fill.
58+
* @param start starting index.
59+
* @param len number of elements to copy
60+
*/
61+
override def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) {
62+
val len1 = len min (xs.length - start) min length
63+
Array.copy(array, 0, xs, start, len1)
64+
}
6865
}
6966

7067
object GenericArray extends SeqFactory[GenericArray] {

src/library/scala/collection/mutable/ResizableArray.scala

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,6 @@ trait ResizableArray[A] extends IndexedSeq[A]
5050
array(idx) = elem.asInstanceOf[AnyRef]
5151
}
5252

53-
/** Fills the given array <code>xs</code> with the elements of
54-
* this sequence starting at position <code>start</code>.
55-
*
56-
* @param xs the array to fill.
57-
* @param start starting index.
58-
*/
59-
override def copyToArray[B >: A](xs: Array[B], start: Int) {
60-
Array.copy(array, 0, xs, start, size0)
61-
}
62-
63-
/** Copy all elements to a buffer
64-
* @param The buffer to which elements are copied
65-
override def copyToBuffer[B >: A](dest: Buffer[B]) {
66-
dest ++= (array: Seq[AnyRef]).asInstanceOf[Seq[B]]
67-
}
68-
*/
69-
7053
override def foreach[U](f: A => U) {
7154
var i = 0
7255
while (i < size) {
@@ -75,6 +58,20 @@ trait ResizableArray[A] extends IndexedSeq[A]
7558
}
7659
}
7760

61+
/** Fills the given array <code>xs</code> with at most `len` elements of
62+
* this traversable starting at position `start`.
63+
* Copying will stop once either the end of the current traversable is reached or
64+
* `len` elements have been copied or the end of the array is reached.
65+
*
66+
* @param xs the array to fill.
67+
* @param start starting index.
68+
* @param len number of elements to copy
69+
*/
70+
override def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) {
71+
val len1 = len min (xs.length - start) min length
72+
Array.copy(array, 0, xs, start, len1)
73+
}
74+
7875
//##########################################################################
7976

8077
/** remove elements of this array at indices after <code>sz</code>

0 commit comments

Comments
 (0)