diff options
author | Josh Suereth <Joshua.Suereth@gmail.com> | 2012-09-17 05:01:22 -0700 |
---|---|---|
committer | Josh Suereth <Joshua.Suereth@gmail.com> | 2012-09-17 05:01:22 -0700 |
commit | 61c83d2903f1c68c943ea646e75b4ca32d75f991 (patch) | |
tree | 0fcf7f24c3538fe0051a83e6f6dc3b3462f86cb6 /src | |
parent | 9bcb335b8a08edb5cd88408e3f5be3fee6a7ca88 (diff) | |
parent | 121f3a92ea86258ab8507c6a7759cd2242bebab6 (diff) | |
download | scala-61c83d2903f1c68c943ea646e75b4ca32d75f991.tar.gz scala-61c83d2903f1c68c943ea646e75b4ca32d75f991.tar.bz2 scala-61c83d2903f1c68c943ea646e75b4ca32d75f991.zip |
Merge pull request #1322 from paulp/topic/emptyArray
Topic/empty array
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/cmd/gen/AnyVals.scala | 8 | ||||
-rw-r--r-- | src/library/scala/Array.scala | 10 | ||||
-rw-r--r-- | src/library/scala/Boolean.scala | 7 | ||||
-rw-r--r-- | src/library/scala/Byte.scala | 8 | ||||
-rw-r--r-- | src/library/scala/Char.scala | 8 | ||||
-rw-r--r-- | src/library/scala/Double.scala | 8 | ||||
-rw-r--r-- | src/library/scala/Float.scala | 8 | ||||
-rw-r--r-- | src/library/scala/Int.scala | 8 | ||||
-rw-r--r-- | src/library/scala/Long.scala | 8 | ||||
-rw-r--r-- | src/library/scala/Short.scala | 8 | ||||
-rw-r--r-- | src/reflect/scala/tools/nsc/io/VirtualFile.scala | 2 | ||||
-rw-r--r-- | src/reflect/scala/tools/nsc/io/ZipArchive.scala | 2 |
12 files changed, 13 insertions, 72 deletions
diff --git a/src/compiler/scala/tools/cmd/gen/AnyVals.scala b/src/compiler/scala/tools/cmd/gen/AnyVals.scala index b4f5641b98..6d652ffdfe 100644 --- a/src/compiler/scala/tools/cmd/gen/AnyVals.scala +++ b/src/compiler/scala/tools/cmd/gen/AnyVals.scala @@ -320,13 +320,7 @@ def unbox(x: java.lang.Object): @name@ = @unboxImpl@ override def toString = "object scala.@name@" """ - def nonUnitCompanions = """ -/** A highly reusable empty array, useful for avoiding - * allocations when you need one. - * - * @return a constant 0-length Array[@name@] - */ -final val emptyArray = new Array[@name@](0)""" + def nonUnitCompanions = "" // todo def cardinalCompanion = """ /** The smallest value representable as a @name@. 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) diff --git a/src/library/scala/Boolean.scala b/src/library/scala/Boolean.scala index d7311078ab..440e546f19 100644 --- a/src/library/scala/Boolean.scala +++ b/src/library/scala/Boolean.scala @@ -135,12 +135,5 @@ object Boolean extends AnyValCompanion { */ override def toString = "object scala.Boolean" - - /** A highly reusable empty array, useful for avoiding - * allocations when you need one. - * - * @return a constant 0-length Array[Boolean] - */ - final val emptyArray = new Array[Boolean](0) } diff --git a/src/library/scala/Byte.scala b/src/library/scala/Byte.scala index 02ef913fc5..df0d2c73b1 100644 --- a/src/library/scala/Byte.scala +++ b/src/library/scala/Byte.scala @@ -625,14 +625,6 @@ object Byte extends AnyValCompanion { */ override def toString = "object scala.Byte" - - /** A highly reusable empty array, useful for avoiding - * allocations when you need one. - * - * @return a constant 0-length Array[Byte] - */ - final val emptyArray = new Array[Byte](0) - /** Language mandated coercions from Byte to "wider" types. */ implicit def byte2short(x: Byte): Short = x.toShort diff --git a/src/library/scala/Char.scala b/src/library/scala/Char.scala index 5a1bf16f1d..1fa0c0d9e8 100644 --- a/src/library/scala/Char.scala +++ b/src/library/scala/Char.scala @@ -625,14 +625,6 @@ object Char extends AnyValCompanion { */ override def toString = "object scala.Char" - - /** A highly reusable empty array, useful for avoiding - * allocations when you need one. - * - * @return a constant 0-length Array[Char] - */ - final val emptyArray = new Array[Char](0) - /** Language mandated coercions from Char to "wider" types. */ implicit def char2int(x: Char): Int = x.toInt diff --git a/src/library/scala/Double.scala b/src/library/scala/Double.scala index 7bebbf9418..f058d7c26b 100644 --- a/src/library/scala/Double.scala +++ b/src/library/scala/Double.scala @@ -400,13 +400,5 @@ object Double extends AnyValCompanion { /** The String representation of the scala.Double companion object. */ override def toString = "object scala.Double" - - - /** A highly reusable empty array, useful for avoiding - * allocations when you need one. - * - * @return a constant 0-length Array[Double] - */ - final val emptyArray = new Array[Double](0) } diff --git a/src/library/scala/Float.scala b/src/library/scala/Float.scala index 79ed2ac20b..d942acec23 100644 --- a/src/library/scala/Float.scala +++ b/src/library/scala/Float.scala @@ -401,14 +401,6 @@ object Float extends AnyValCompanion { */ override def toString = "object scala.Float" - - /** A highly reusable empty array, useful for avoiding - * allocations when you need one. - * - * @return a constant 0-length Array[Float] - */ - final val emptyArray = new Array[Float](0) - /** Language mandated coercions from Float to "wider" types. */ implicit def float2double(x: Float): Double = x.toDouble diff --git a/src/library/scala/Int.scala b/src/library/scala/Int.scala index fa2f9a97e7..ae36413469 100644 --- a/src/library/scala/Int.scala +++ b/src/library/scala/Int.scala @@ -625,14 +625,6 @@ object Int extends AnyValCompanion { */ override def toString = "object scala.Int" - - /** A highly reusable empty array, useful for avoiding - * allocations when you need one. - * - * @return a constant 0-length Array[Int] - */ - final val emptyArray = new Array[Int](0) - /** Language mandated coercions from Int to "wider" types. */ implicit def int2long(x: Int): Long = x.toLong diff --git a/src/library/scala/Long.scala b/src/library/scala/Long.scala index 94204e893c..4ee9383c2a 100644 --- a/src/library/scala/Long.scala +++ b/src/library/scala/Long.scala @@ -625,14 +625,6 @@ object Long extends AnyValCompanion { */ override def toString = "object scala.Long" - - /** A highly reusable empty array, useful for avoiding - * allocations when you need one. - * - * @return a constant 0-length Array[Long] - */ - final val emptyArray = new Array[Long](0) - /** Language mandated coercions from Long to "wider" types. */ implicit def long2float(x: Long): Float = x.toFloat diff --git a/src/library/scala/Short.scala b/src/library/scala/Short.scala index aef8608d2e..35c5fe3ff0 100644 --- a/src/library/scala/Short.scala +++ b/src/library/scala/Short.scala @@ -625,14 +625,6 @@ object Short extends AnyValCompanion { */ override def toString = "object scala.Short" - - /** A highly reusable empty array, useful for avoiding - * allocations when you need one. - * - * @return a constant 0-length Array[Short] - */ - final val emptyArray = new Array[Short](0) - /** Language mandated coercions from Short to "wider" types. */ implicit def short2int(x: Short): Int = x.toInt diff --git a/src/reflect/scala/tools/nsc/io/VirtualFile.scala b/src/reflect/scala/tools/nsc/io/VirtualFile.scala index 9061534edc..8a5114bfe7 100644 --- a/src/reflect/scala/tools/nsc/io/VirtualFile.scala +++ b/src/reflect/scala/tools/nsc/io/VirtualFile.scala @@ -33,7 +33,7 @@ class VirtualFile(val name: String, override val path: String) extends AbstractF //######################################################################## // Private data - private var content = Byte.emptyArray + private var content = Array.emptyByteArray //######################################################################## // Public Methods diff --git a/src/reflect/scala/tools/nsc/io/ZipArchive.scala b/src/reflect/scala/tools/nsc/io/ZipArchive.scala index 9d9d9a46f2..49d2200895 100644 --- a/src/reflect/scala/tools/nsc/io/ZipArchive.scala +++ b/src/reflect/scala/tools/nsc/io/ZipArchive.scala @@ -177,7 +177,7 @@ final class URLZipArchive(val url: URL) extends ZipArchive(null) { class FileEntry() extends Entry(zipEntry.getName) { override val toByteArray: Array[Byte] = { val len = zipEntry.getSize().toInt - val arr = if (len == 0) Byte.emptyArray else new Array[Byte](len) + val arr = if (len == 0) Array.emptyByteArray else new Array[Byte](len) var offset = 0 def loop() { |