diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-10-30 08:42:53 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-11-08 11:39:11 +0100 |
commit | db4ef5b78be2fb7f954d82a972ab70df28acccfa (patch) | |
tree | bc5abbabba1d6d7be89ed5ea2e3e05589e80c340 /src/compiler | |
parent | 12fe8ef2aff8760a9f0277a7baf74a011753f788 (diff) | |
download | scala-db4ef5b78be2fb7f954d82a972ab70df28acccfa.tar.gz scala-db4ef5b78be2fb7f954d82a972ab70df28acccfa.tar.bz2 scala-db4ef5b78be2fb7f954d82a972ab70df28acccfa.zip |
Avoid needless TypeRef allocation during erasure.
- ThisType(some.package) need not be erased, we can let
that prefix through unchanged and avoid churning through
allocations.
- Sharpen the condition in `rebindInnerClass`. The answer
to the deleted comment in the code, is "anonymous and
local classes", which are specifically excluded in the
new formulation.
- Finally, detect if erasure of the TypeRef is an identity and reuse
the original.
Waste not, want not.
To expand on the first point, here is what used to happen during
erasure:
scala> val scalaPack = typeOf[Predef.type].prefix
scalaPack: $r.intp.global.Type = scala.type
scala> typeDeconstruct.show(scalaPack)
res19: String = ThisType(package scala)
scala> typeDeconstruct.show(erasure.scalaErasure(scalaPack))
res20: String = TypeRef(TypeSymbol(final class scala extends ))
Showing one step of the erasure type map:
scala> typeDeconstruct.show(scalaPack.asInstanceOf[SubType].underlying.typeOfThis)
res21: String = SingleType(pre = ThisType(package <root>), package scala)
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Erasure.scala | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index a4854dfbeb..57f3da839a 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -1043,7 +1043,7 @@ abstract class Erasure extends AddInterfaces case Literal(ct) if ct.tag == ClazzTag && ct.typeValue.typeSymbol != definitions.UnitClass => val erased = ct.typeValue match { - case TypeRef(pre, clazz, args) if clazz.isDerivedValueClass => scalaErasure.eraseNormalClassRef(pre, clazz) + case tr @ TypeRef(pre, clazz, args) if clazz.isDerivedValueClass => scalaErasure.eraseNormalClassRef(tr) case tpe => specialScalaErasure(tpe) } treeCopy.Literal(tree, Constant(erased)) |