diff options
author | Paul Phillips <paulp@improving.org> | 2012-09-14 10:54:23 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-09-14 10:59:41 -0700 |
commit | 9d84e89d27c396203e84f6ae685863210ebc1968 (patch) | |
tree | 09793479707c30d70ca3f6353157bcca003bc0f4 /src/compiler | |
parent | f68201c469725c255ae2786f0ac1e37bc5f30a7a (diff) | |
download | scala-9d84e89d27c396203e84f6ae685863210ebc1968.tar.gz scala-9d84e89d27c396203e84f6ae685863210ebc1968.tar.bz2 scala-9d84e89d27c396203e84f6ae685863210ebc1968.zip |
Added constant empty array to the companion objects.
Because there are lots of times when you just need an
array and shouldn't have to allocate one every time or
pick a random spot to cache yet another empty array.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/cmd/gen/AnyVals.scala | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/cmd/gen/AnyVals.scala b/src/compiler/scala/tools/cmd/gen/AnyVals.scala index 7842603af7..3f8283590c 100644 --- a/src/compiler/scala/tools/cmd/gen/AnyVals.scala +++ b/src/compiler/scala/tools/cmd/gen/AnyVals.scala @@ -14,7 +14,7 @@ trait AnyValReps { sealed abstract class AnyValNum(name: String, repr: Option[String], javaEquiv: String) extends AnyValRep(name,repr,javaEquiv) { case class Op(val op : String, val doc : String) - + private def companionCoercions(tos: AnyValRep*) = { tos.toList map (to => """implicit def @javaequiv@2%s(x: @name@): %s = x.to%s""".format(to.javaEquiv, to.name, to.name) @@ -24,7 +24,7 @@ trait AnyValReps { def coercionComment = """ /** Language mandated coercions from @name@ to "wider" types.%s */""".format(coercionCommentExtra) - + def implicitCoercions: List[String] = { val coercions = this match { case B => companionCoercions(S, I, L, F, D) @@ -247,7 +247,7 @@ trait AnyValReps { def classDoc = interpolate(classDocTemplate) def objectDoc = "" def mkImports = "" - + def mkClass = assemble("final abstract class " + name + " private extends AnyVal", classLines) def mkObject = assemble("object " + name + " extends AnyValCompanion", objectLines) def make() = List[String]( @@ -320,7 +320,13 @@ def unbox(x: java.lang.Object): @name@ = @unboxImpl@ override def toString = "object scala.@name@" """ - def nonUnitCompanions = "" // todo + 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 cardinalCompanion = """ /** The smallest value representable as a @name@. @@ -341,9 +347,6 @@ final val NaN = @boxed@.NaN final val PositiveInfinity = @boxed@.POSITIVE_INFINITY final val NegativeInfinity = @boxed@.NEGATIVE_INFINITY -@deprecated("use @name@.MinPositiveValue instead", "2.9.0") -final val Epsilon = MinPositiveValue - /** The negative number with the greatest (finite) absolute value which is representable * by a @name@. Note that it differs from [[java.lang.@name@.MIN_VALUE]], which * is the smallest positive value representable by a @name@. In Scala that number |