summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@typesafe.com>2015-11-24 15:47:40 +0100
committerLukas Rytz <lukas.rytz@typesafe.com>2015-11-24 15:47:40 +0100
commit2ef93ad2fe29766fbe09a3e921ad361b25abdeaf (patch)
tree6d0f7e93b18b677207df4243042d24721393684d
parente8f3836578c5153fae3f9ded7c4afec6d6d3a6f8 (diff)
parentf5f777e6ce94e4e105ee70463e63d2238dedd2be (diff)
downloadscala-2ef93ad2fe29766fbe09a3e921ad361b25abdeaf.tar.gz
scala-2ef93ad2fe29766fbe09a3e921ad361b25abdeaf.tar.bz2
scala-2ef93ad2fe29766fbe09a3e921ad361b25abdeaf.zip
Merge pull request #4863 from retronym/topic/leaner-patmat-codegen
DRY-er trees in pattern matcher code gen.
-rw-r--r--src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala10
-rw-r--r--test/files/run/t6288.check14
2 files changed, 13 insertions, 11 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..af536cb2d3 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchCodeGen.scala
@@ -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
}
diff --git a/test/files/run/t6288.check b/test/files/run/t6288.check
index a032a10de6..67877fd56d 100644
--- a/test/files/run/t6288.check
+++ b/test/files/run/t6288.check
@@ -33,11 +33,8 @@
[175]case <synthetic> val x1: [175]Any = [175]"";
[175]case5()[195]{
[195]<synthetic> val o7: [195]Option[List[Int]] = [195][195]Case4.unapplySeq([195]x1);
- [195]if ([195]o7.isEmpty.unary_!)
- [195]if ([195][195][195][195]o7.get.!=([195]null).&&([195][195][195][195]o7.get.lengthCompare([195]1).==([195]0)))
- [208][208]matchEnd4([208]())
- else
- [195][195]case6()
+ [195]if ([195][195]o7.isEmpty.unary_!.&&([195][195][195][195]o7.get.!=([195]null).&&([195][195][195][195]o7.get.lengthCompare([195]1).==([195]0))))
+ [208][208]matchEnd4([208]())
else
[195][195]case6()
};
@@ -59,11 +56,8 @@
[273]case <synthetic> val x1: [273]Any = [273]"";
[273]case5()[293]{
[293]<synthetic> val o7: [293]Option[List[Int]] = [293][293]Case4.unapplySeq([293]x1);
- [293]if ([293]o7.isEmpty.unary_!)
- [293]if ([293][293][293][293]o7.get.!=([293]null).&&([293][293][293][293]o7.get.lengthCompare([293]0).==([293]0)))
- [304][304]matchEnd4([304]())
- else
- [293][293]case6()
+ [293]if ([293][293]o7.isEmpty.unary_!.&&([293][293][293][293]o7.get.!=([293]null).&&([293][293][293][293]o7.get.lengthCompare([293]0).==([293]0))))
+ [304][304]matchEnd4([304]())
else
[293][293]case6()
};