From db4ef5b78be2fb7f954d82a972ab70df28acccfa Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 30 Oct 2013 08:42:53 +0100 Subject: 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 ), package scala) --- test/files/run/t6028.check | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/files/run') diff --git a/test/files/run/t6028.check b/test/files/run/t6028.check index b37bf51d73..a6c4db8f11 100644 --- a/test/files/run/t6028.check +++ b/test/files/run/t6028.check @@ -24,7 +24,7 @@ package { (new <$anon: Function0>(T.this, tryyParam, tryyLocal): Function0) } }; - @SerialVersionUID(0) final class $anonfun$foo$1 extends runtime.AbstractFunction0$mcI$sp with Serializable { + @SerialVersionUID(0) final class $anonfun$foo$1 extends scala.runtime.AbstractFunction0$mcI$sp with Serializable { def ($outer: T, methodParam$1: Int, methodLocal$1: Int): <$anon: Function0> = { $anonfun$foo$1.super.(); () @@ -60,7 +60,7 @@ package { }; scala.this.Predef.print(scala.Int.box(barParam$1)) }; - @SerialVersionUID(0) final class $anonfun$tryy$1 extends runtime.AbstractFunction0$mcV$sp with Serializable { + @SerialVersionUID(0) final class $anonfun$tryy$1 extends scala.runtime.AbstractFunction0$mcV$sp with Serializable { def ($outer: T, tryyParam$1: Int, tryyLocal$1: runtime.IntRef): <$anon: Function0> = { $anonfun$tryy$1.super.(); () -- cgit v1.2.3