summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/mutable/WrappedArrayBuilder.scala
diff options
context:
space:
mode:
authorRex Kerr <ichoran@gmail.com>2016-01-14 15:14:53 -0800
committerRex Kerr <ichoran@gmail.com>2016-01-30 18:32:27 -0800
commit6eaae1b969b68ed3dc65a40613a8168b09246256 (patch)
tree35118267c53111a2f9ce7e2a0ddde0ff903fa2eb /src/library/scala/collection/mutable/WrappedArrayBuilder.scala
parent78f0437ac06e71a94a38721751ef5d36ca62c062 (diff)
downloadscala-6eaae1b969b68ed3dc65a40613a8168b09246256.tar.gz
scala-6eaae1b969b68ed3dc65a40613a8168b09246256.tar.bz2
scala-6eaae1b969b68ed3dc65a40613a8168b09246256.zip
Clarified and expanded which Builders were reusable
This additionally fixes both SI-8648 and SI-9564. Added documentation to Builder to clarify that in general Builders are NOT reusable. Altered implementation of GrowingBuilder to use Growable instance's clear (not valid for a reusable builder, but this one isn't reusable). Added a new marker trait ReusableBuilder that specifies that these builders should be reusable. This trait overrides the clear and result methods while leaving them abstract in order to supply appropriate scaladoc. Made all Array builders Reusable in all cases (by setting capacity to 0 if the original array is returned). (Fixed a poor implmentation of Array[Unit] builder along the way.) Documented which other builders were already reusable (maps, sets, Vector, LazyBuilder, StringBuilder, ListBuffer, etc.).
Diffstat (limited to 'src/library/scala/collection/mutable/WrappedArrayBuilder.scala')
-rw-r--r--src/library/scala/collection/mutable/WrappedArrayBuilder.scala13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/library/scala/collection/mutable/WrappedArrayBuilder.scala b/src/library/scala/collection/mutable/WrappedArrayBuilder.scala
index bfe95a11ab..c4781321d7 100644
--- a/src/library/scala/collection/mutable/WrappedArrayBuilder.scala
+++ b/src/library/scala/collection/mutable/WrappedArrayBuilder.scala
@@ -17,12 +17,14 @@ import scala.runtime.ScalaRunTime._
/** A builder class for arrays.
*
+ * This builder can be reused.
+ *
* @tparam A type of elements that can be added to this builder.
* @param tag class tag for objects of type `A`.
*
* @since 2.8
*/
-class WrappedArrayBuilder[A](tag: ClassTag[A]) extends Builder[A, WrappedArray[A]] {
+class WrappedArrayBuilder[A](tag: ClassTag[A]) extends ReusableBuilder[A, WrappedArray[A]] {
@deprecated("use tag instead", "2.10.0")
val manifest: ClassTag[A] = tag
@@ -73,12 +75,13 @@ class WrappedArrayBuilder[A](tag: ClassTag[A]) extends Builder[A, WrappedArray[A
this
}
- def clear() {
- size = 0
- }
+ def clear() { size = 0 }
def result() = {
- if (capacity != 0 && capacity == size) elems
+ if (capacity != 0 && capacity == size) {
+ capacity = 0
+ elems
+ }
else mkArray(size)
}