diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala index 1642613b9b..03d0a28fb1 100644 --- a/src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala +++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala @@ -6,9 +6,9 @@ package scala.tools.nsc.transform.patmat -import scala.tools.nsc.symtab.Flags.SYNTHETIC import scala.language.postfixOps -import scala.reflect.internal.util.Statistics + +import scala.tools.nsc.symtab.Flags.SYNTHETIC import scala.reflect.internal.util.Position /** Factory methods used by TreeMakers to make the actual trees. @@ -55,7 +55,15 @@ trait MatchCodeGen extends Interface { def flatMap(prev: Tree, b: Symbol, next: Tree): Tree def flatMapCond(cond: Tree, res: Tree, nextBinder: Symbol, next: Tree): Tree def flatMapGuard(cond: Tree, next: Tree): Tree - def ifThenElseZero(c: Tree, thenp: Tree): Tree = IF (c) THEN thenp ELSE zero + def ifThenElseZero(c: Tree, thenp: Tree): Tree = { + val z = zero + thenp match { + case If(c1, thenp1, elsep1) if z equalsStructure elsep1 => + If(c AND c1, thenp1, elsep1) // cleaner, leaner trees + case _ => + If(c, thenp, zero) + } + } protected def zero: Tree } |