summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/Constructors.scala
diff options
context:
space:
mode:
authorMiguel Garcia <miguelalfredo.garcia@epfl.ch>2013-07-08 22:22:23 +0200
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-08-08 12:09:49 -0700
commit858615813714aa7c34fe6ce1749dcdd595750a2e (patch)
tree0496cb62f76bed301098e0a060594ead3975f24e /src/compiler/scala/tools/nsc/transform/Constructors.scala
parent053682c53c5a2b7f2c37f08727a2c1c330480899 (diff)
downloadscala-858615813714aa7c34fe6ce1749dcdd595750a2e.tar.gz
scala-858615813714aa7c34fe6ce1749dcdd595750a2e.tar.bz2
scala-858615813714aa7c34fe6ce1749dcdd595750a2e.zip
skipping trips to specializeTypes when not necessary in constructors
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/Constructors.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/Constructors.scala16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala
index 83cc2ba5c7..a652931f3e 100644
--- a/src/compiler/scala/tools/nsc/transform/Constructors.scala
+++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala
@@ -442,7 +442,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
@@ -522,6 +522,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
// A transformer for expressions that go into the constructor
@@ -564,9 +573,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 _ =>