Skip to content

Commit 37eec59

Browse files
paulpadriaanm
authored andcommitted
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!
1 parent 8586158 commit 37eec59

File tree

1 file changed

+20
-37
lines changed

1 file changed

+20
-37
lines changed

src/compiler/scala/tools/nsc/transform/Constructors.scala

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -173,50 +173,33 @@ abstract class Constructors extends Transform with ast.TreeDSL {
173173
omittables ++= paramCandidatesForElision
174174
omittables ++= outerCandidatesForElision
175175

176-
val bodyOfOuterAccessor: Map[Symbol, DefDef] = {
177-
val outers = (defBuf collect { case dd: DefDef if outerCandidatesForElision.contains(dd.symbol) => dd })
178-
Map(outers.map { dd => (dd.symbol, dd) } : _*)
179-
}
180-
181-
class UsagesDetector extends Traverser {
182-
var done = false
183-
override def traverse(tree: Tree) {
184-
if (done) { return }
176+
val bodyOfOuterAccessor: Map[Symbol, DefDef] =
177+
defBuf collect { case dd: DefDef if outerCandidatesForElision(dd.symbol) => dd.symbol -> dd } toMap
178+
179+
// no point traversing further once omittables is empty, all candidates ruled out already.
180+
object detectUsages extends Traverser {
181+
private def markUsage(sym: Symbol) {
182+
omittables -= debuglogResult("omittables -= ")(sym)
183+
// recursive call to mark as needed the field supporting the outer-accessor-method.
184+
bodyOfOuterAccessor get sym foreach (this traverse _.rhs)
185+
}
186+
override def traverse(tree: Tree): Unit = if (omittables.nonEmpty) {
187+
def sym = tree.symbol
185188
tree match {
186-
case DefDef(_, _, _, _, _, body) if outerCandidatesForElision.contains(tree.symbol) =>
187-
() // don't mark as "needed" the field supporting this outer-accessor, ie not just yet.
188-
case Select(_, _) =>
189-
val sym = tree.symbol
190-
if (omittables contains sym) {
191-
debuglog("omittables -= " + sym.fullName)
192-
omittables -= sym
193-
bodyOfOuterAccessor.get(sym) match {
194-
case Some(dd) => traverse(dd.rhs) // recursive call to mark as needed the field supporting the outer-accessor-method.
195-
case _ => ()
196-
}
197-
if (omittables.isEmpty) {
198-
done = true
199-
return // no point traversing further, all candidates ruled out already.
200-
}
201-
}
202-
super.traverse(tree)
203-
case _ =>
204-
super.traverse(tree)
189+
// don't mark as "needed" the field supporting this outer-accessor, ie not just yet.
190+
case _: DefDef if outerCandidatesForElision(sym) => ()
191+
case _: Select if omittables(sym) => markUsage(sym) ; super.traverse(tree)
192+
case _ => super.traverse(tree)
205193
}
206194
}
195+
def walk(xs: Seq[Tree]) = xs.iterator foreach traverse
207196
}
208-
209197
if (omittables.nonEmpty) {
210-
val usagesDetector = new UsagesDetector
211-
212-
for (stat <- defBuf.iterator ++ auxConstructorBuf.iterator) {
213-
usagesDetector.traverse(stat)
214-
}
198+
detectUsages walk defBuf
199+
detectUsages walk auxConstructorBuf
215200
}
216-
217201
}
218-
219-
def mustbeKept(sym: Symbol) = (!omittables(sym))
202+
def mustbeKept(sym: Symbol) = !omittables(sym)
220203

221204
} // OmittablesHelper
222205

0 commit comments

Comments
 (0)