diff options
author | Paul Phillips <paulp@improving.org> | 2011-01-05 23:39:35 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-01-05 23:39:35 +0000 |
commit | fdb1e699911ccf4467c6663a799736e42c18eb83 (patch) | |
tree | 7075958fcbdd150cca61a7e78849adcce9b8078c /src/library/scala/LowPriorityImplicits.scala | |
parent | 6915e7e999f4fac555e0bb066c787191575a40ed (diff) | |
download | scala-fdb1e699911ccf4467c6663a799736e42c18eb83.tar.gz scala-fdb1e699911ccf4467c6663a799736e42c18eb83.tar.bz2 scala-fdb1e699911ccf4467c6663a799736e42c18eb83.zip |
Avoids the creation of an amazing 106,700,793 e...
Avoids the creation of an amazing 106,700,793 empty arrays (I counted
on my fingers) during the compilation of quick.lib and quick.comp by
reusing an empty Array[Object]. (And another ten million or so after
quick.comp, but who is counting.) It sounds like it would make a bigger
difference than it does. Also eliminated some strange indirection from
WrappedArray to LowPriorityImplicits back to WrappedArray on each
creation.
Review by dragos.
Diffstat (limited to 'src/library/scala/LowPriorityImplicits.scala')
-rw-r--r-- | src/library/scala/LowPriorityImplicits.scala | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/library/scala/LowPriorityImplicits.scala b/src/library/scala/LowPriorityImplicits.scala index 0182ecdae9..6fce638061 100644 --- a/src/library/scala/LowPriorityImplicits.scala +++ b/src/library/scala/LowPriorityImplicits.scala @@ -37,9 +37,18 @@ class LowPriorityImplicits { implicit def booleanWrapper(x: Boolean) = new runtime.RichBoolean(x) implicit def genericWrapArray[T](xs: Array[T]): WrappedArray[T] = - if (xs ne null) WrappedArray.make(xs) else null + if (xs eq null) null + else WrappedArray.make(xs) + + // Since the JVM thinks arrays are covariant, one 0-length Array[AnyRef] + // is as good as another for all T <: AnyRef. Instead of creating 100,000,000 + // unique ones by way of this implicit, let's share one. + implicit def wrapRefArray[T <: AnyRef](xs: Array[T]): WrappedArray[T] = { + if (xs eq null) null + else if (xs.length == 0) WrappedArray.empty[T] + else new WrappedArray.ofRef[T](xs) + } - implicit def wrapRefArray[T <: AnyRef](xs: Array[T]): WrappedArray[T] = if (xs ne null) new WrappedArray.ofRef[T](xs) else null implicit def wrapIntArray(xs: Array[Int]): WrappedArray[Int] = if (xs ne null) new WrappedArray.ofInt(xs) else null implicit def wrapDoubleArray(xs: Array[Double]): WrappedArray[Double] = if (xs ne null) new WrappedArray.ofDouble(xs) else null implicit def wrapLongArray(xs: Array[Long]): WrappedArray[Long] = if (xs ne null) new WrappedArray.ofLong(xs) else null |