diff options
author | Paul Phillips <paulp@improving.org> | 2010-03-30 21:25:16 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-03-30 21:25:16 +0000 |
commit | e7e15da74c1c9a81f419b640c79c636e704b8ed5 (patch) | |
tree | c1bbb79db47b75cb915f9094d30e93cef260f84c | |
parent | 0e7403eea2e7082a255ad258c8d2a38c6156f476 (diff) | |
download | scala-e7e15da74c1c9a81f419b640c79c636e704b8ed5.tar.gz scala-e7e15da74c1c9a81f419b640c79c636e704b8ed5.tar.bz2 scala-e7e15da74c1c9a81f419b640c79c636e704b8ed5.zip |
Noticed that the implementation of toArray Iter...
Noticed that the implementation of toArray Iterator had acquired via
TraversableOnce called "size" to allocate the array, leaving a nice
empty iterator to actually populate it. Fixed. No review.
-rw-r--r-- | src/library/scala/collection/TraversableOnce.scala | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala index 2224f534ad..6e4917b77e 100644 --- a/src/library/scala/collection/TraversableOnce.scala +++ b/src/library/scala/collection/TraversableOnce.scala @@ -378,9 +378,12 @@ trait TraversableOnce[+A] { * A `ClassManifest` must be available for the element type of this $coll. */ def toArray[B >: A : ClassManifest]: Array[B] = { - val result = new Array[B](size) - copyToArray(result, 0) - result + if (isTraversableAgain) { + val result = new Array[B](size) + copyToArray(result, 0) + result + } + else toStream.toArray } /** Converts this $coll to a list. |