diff options
author | Paul Phillips <paulp@improving.org> | 2012-09-16 20:44:56 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-09-16 20:53:59 -0700 |
commit | d918144f16111358a61d6f5f847227946bcc17a9 (patch) | |
tree | 55dd3ae2790e5ed453575205f83a700b6732dcd4 /src/library | |
parent | 5cf6a750eac94d159fe4c67b75e24dde13495e71 (diff) | |
download | scala-d918144f16111358a61d6f5f847227946bcc17a9.tar.gz scala-d918144f16111358a61d6f5f847227946bcc17a9.tar.bz2 scala-d918144f16111358a61d6f5f847227946bcc17a9.zip |
Moved constant empty arrays into Array companion.
This reminds me of at least one reason I didn't put them
here before: I don't feel like I can return these from calls
to Array.empty, because there's no way of knowing whether
anyone has been relying upon this property:
scala> Array.empty[Byte] eq Array.empty[Byte]
res0: Boolean = false
Since that is exactly the property I need to alter.
The test above is true in all the "real" collections,
which is all the more reason to be concerned that someone
might be using empty arrays as not-equivalent sentinels.
I can still move them here, but it'd be a lot better if
array creation could use them - not only def empty but
def apply[T: ClassTag](xs: T*): Array[T]
which probably creates millions of empty arrays where
one would do in almost every case.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/Array.scala | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala index c61a255e3b..0b8550be37 100644 --- a/src/library/scala/Array.scala +++ b/src/library/scala/Array.scala @@ -48,6 +48,16 @@ class FallbackArrayBuilding { * @version 1.0 */ object Array extends FallbackArrayBuilding { + val emptyBooleanArray = new Array[Boolean](0) + val emptyByteArray = new Array[Byte](0) + val emptyCharArray = new Array[Char](0) + val emptyDoubleArray = new Array[Double](0) + val emptyFloatArray = new Array[Float](0) + val emptyIntArray = new Array[Int](0) + val emptyLongArray = new Array[Long](0) + val emptyShortArray = new Array[Short](0) + val emptyObjectArray = new Array[Object](0) + implicit def canBuildFrom[T](implicit t: ClassTag[T]): CanBuildFrom[Array[_], T, Array[T]] = new CanBuildFrom[Array[_], T, Array[T]] { def apply(from: Array[_]) = ArrayBuilder.make[T]()(t) |