summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-05-26 20:16:10 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-08-08 12:09:49 -0700
commit37eec59149061334503ae78146170676d5ce2154 (patch)
treeb1b082ccca9c7eeface932e39cb71303fc80319e /src
parent858615813714aa7c34fe6ce1749dcdd595750a2e (diff)
downloadscala-37eec59149061334503ae78146170676d5ce2154.tar.gz
scala-37eec59149061334503ae78146170676d5ce2154.tar.bz2
scala-37eec59149061334503ae78146170676d5ce2154.zip
Golfed about 20 lines into the sand trap.
And it's a nice golf clinic and all, but let's remove our golf gloves and take in some film. for (stat <- defBuf.iterator ++ auxConstructorBuf.iterator) A quick count: - defBuf is a ListBuffer (1 mutant) - auxConstructorBuf is a ListBuffer (2 mutants) - two mutable iterators over mutable sequences (3, 4 mutants) - Iterator.++ joins them and is BY-NAME (4 mutants, 1 tragedy in waiting) - the joined Iterator is a new mutable structure (5 mutants, now 3 deep) - omittables is a mutable Set (6 mutants) - the 5-layer-3-deep iterator mutates omittables as it walks [The following is a public service breakdown. The letter sequence y-o-u is a local variable which should be replaced with your name, whoever "you" are, if you commit any code in these parts.] Hear my plea! YOU DON'T HAVE TO DO IT THIS WAY! It isn't simpler, faster, easier, more satisfying, shorter, more pixelated, there just isn't any advantage to it, even if you're lazy! Especially if you're lazy! Whatever combination of virtues and vices exist in your personal petri dish, this will never be a hilltop! PLEASE COME ENJOY A DRINK WITH ME AND MY FRIEND 'VAL' !! I'LL INTRODUCE YOU! I THINK YOU WILL REALLY LIKE HER! I HOPE YOU WILL SEE A LOT OF ONE ANOTHER! REMEMBER THAT NAME, 'VAL' !! SHE'LL HAVE HER EYE OUT FOR YOU!
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/transform/Constructors.scala57
1 files changed, 20 insertions, 37 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala
index a652931f3e..e80117afbd 100644
--- a/src/compiler/scala/tools/nsc/transform/Constructors.scala
+++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala
@@ -173,50 +173,33 @@ abstract class Constructors extends Transform with ast.TreeDSL {
omittables ++= paramCandidatesForElision
omittables ++= outerCandidatesForElision
- val bodyOfOuterAccessor: Map[Symbol, DefDef] = {
- val outers = (defBuf collect { case dd: DefDef if outerCandidatesForElision.contains(dd.symbol) => dd })
- Map(outers.map { dd => (dd.symbol, dd) } : _*)
- }
-
- class UsagesDetector extends Traverser {
- var done = false
- override def traverse(tree: Tree) {
- if (done) { return }
+ val bodyOfOuterAccessor: Map[Symbol, DefDef] =
+ defBuf collect { case dd: DefDef if outerCandidatesForElision(dd.symbol) => dd.symbol -> dd } toMap
+
+ // no point traversing further once omittables is empty, all candidates ruled out already.
+ object detectUsages extends Traverser {
+ private def markUsage(sym: Symbol) {
+ omittables -= debuglogResult("omittables -= ")(sym)
+ // recursive call to mark as needed the field supporting the outer-accessor-method.
+ bodyOfOuterAccessor get sym foreach (this traverse _.rhs)
+ }
+ override def traverse(tree: Tree): Unit = if (omittables.nonEmpty) {
+ def sym = tree.symbol
tree match {
- case DefDef(_, _, _, _, _, body) if outerCandidatesForElision.contains(tree.symbol) =>
- () // don't mark as "needed" the field supporting this outer-accessor, ie not just yet.
- case Select(_, _) =>
- val sym = tree.symbol
- if (omittables contains sym) {
- debuglog("omittables -= " + sym.fullName)
- omittables -= sym
- bodyOfOuterAccessor.get(sym) match {
- case Some(dd) => traverse(dd.rhs) // recursive call to mark as needed the field supporting the outer-accessor-method.
- case _ => ()
- }
- if (omittables.isEmpty) {
- done = true
- return // no point traversing further, all candidates ruled out already.
- }
- }
- super.traverse(tree)
- case _ =>
- super.traverse(tree)
+ // don't mark as "needed" the field supporting this outer-accessor, ie not just yet.
+ case _: DefDef if outerCandidatesForElision(sym) => ()
+ case _: Select if omittables(sym) => markUsage(sym) ; super.traverse(tree)
+ case _ => super.traverse(tree)
}
}
+ def walk(xs: Seq[Tree]) = xs.iterator foreach traverse
}
-
if (omittables.nonEmpty) {
- val usagesDetector = new UsagesDetector
-
- for (stat <- defBuf.iterator ++ auxConstructorBuf.iterator) {
- usagesDetector.traverse(stat)
- }
+ detectUsages walk defBuf
+ detectUsages walk auxConstructorBuf
}
-
}
-
- def mustbeKept(sym: Symbol) = (!omittables(sym))
+ def mustbeKept(sym: Symbol) = !omittables(sym)
} // OmittablesHelper