From 478e31a72f72e803d8716b30170dff8de0c40af9 Mon Sep 17 00:00:00 2001 From: Miguel Garcia Date: Thu, 23 May 2013 20:08:34 +0200 Subject: skipping trips to specializeTypes when not necessary in constructors --- .../scala/tools/nsc/transform/Constructors.scala | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala index f93d26360e..cf2b6d39a2 100644 --- a/src/compiler/scala/tools/nsc/transform/Constructors.scala +++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala @@ -279,7 +279,6 @@ abstract class Constructors extends Transform with ast.TreeDSL { delayedDD.asInstanceOf[DefDef] } - /* @see overview at `delayedEndpointDef()` of the translation scheme for DelayedInit */ private def delayedInitClosure(delayedEndPointSym: MethodSymbol): ClassDef = { val satelliteClass = localTyper.typed { atPos(impl.pos) { @@ -327,7 +326,6 @@ abstract class Constructors extends Transform with ast.TreeDSL { satelliteClass.asInstanceOf[ClassDef] } - /* @see overview at `delayedEndpointDef()` of the translation scheme for DelayedInit */ private def delayedInitCall(closure: Tree) = localTyper.typedPos(impl.pos) { gen.mkMethodCall(This(clazz), delayedInitMethod, Nil, List(New(closure.symbol.tpe, This(clazz)))) } @@ -446,7 +444,7 @@ abstract class Constructors extends Transform with ast.TreeDSL { // postfix = postfix.tail // } - if (usesSpecializedField && shouldGuard && stats.nonEmpty) { + if (shouldGuard && usesSpecializedField && stats.nonEmpty) { // save them for duplication in the specialized subclass guardedCtorStats(clazz) = stats ctorParams(clazz) = constrInfo.constrParams @@ -526,6 +524,15 @@ abstract class Constructors extends Transform with ast.TreeDSL { } } + /* + * `usesSpecializedField` makes a difference in deciding whether constructor-statements + * should be guarded in a `shouldGuard` class, ie in a class that's the generic super-class of + * one or more specialized sub-classes. + * + * Given that `usesSpecializedField` isn't read for any other purpose than the one described above, + * we skip setting `usesSpecializedField` in case the current class isn't `shouldGuard` to start with. + * That way, trips to a map in `specializeTypes` are saved. + */ var usesSpecializedField: Boolean = false /* @@ -572,9 +579,10 @@ abstract class Constructors extends Transform with ast.TreeDSL { // references to parameter accessor field of own class become references to parameters gen.mkAttributedIdent(parameter(tree.symbol)) setPos tree.pos - case Select(_, _) => - if (possiblySpecialized(tree.symbol)) + case Select(_, _) if shouldGuard => // reasoning behind this guard in the docu of `usesSpecializedField` + if (possiblySpecialized(tree.symbol)) { usesSpecializedField = true + } super.transform(tree) case _ => -- cgit v1.2.3