summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-05-26 20:16:10 -0700
committerPaul Phillips <paulp@improving.org>2013-05-26 20:56:09 -0700
commit073cc200b165704746e64511b14e68b1a878f493 (patch)
tree5b437b0d4a84778975078821374634c87e71b720 /src/compiler
parent0ee622f8094f9d3e063264f7917676e59fa40f0b (diff)
downloadscala-073cc200b165704746e64511b14e68b1a878f493.tar.gz
scala-073cc200b165704746e64511b14e68b1a878f493.tar.bz2
scala-073cc200b165704746e64511b14e68b1a878f493.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/compiler')
-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 9718631caf..256bc4bae0 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