summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/TailCalls.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-10-08 11:28:10 +1000
committerJason Zaugg <jzaugg@gmail.com>2014-10-10 15:23:39 +1000
commitd6cb47cbc4bc5468b42eda87a90c865728b84c6a (patch)
treee5ad711a3a6b0b23c9fb30071c205a1c82d99ae8 /src/compiler/scala/tools/nsc/transform/TailCalls.scala
parenta52b9a776bdcd01d0b706727bc89e060817137aa (diff)
downloadscala-d6cb47cbc4bc5468b42eda87a90c865728b84c6a.tar.gz
scala-d6cb47cbc4bc5468b42eda87a90c865728b84c6a.tar.bz2
scala-d6cb47cbc4bc5468b42eda87a90c865728b84c6a.zip
Wider use of mapConserve and the like in TailCalls
Save the Trees! When a subtransform is an identity, we must strive to return the identical tree to enable the lazy part of LazyTreeCopier. If we get this wrong in a leaf, all parents are wastefully copied.
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/TailCalls.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/TailCalls.scala7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/TailCalls.scala b/src/compiler/scala/tools/nsc/transform/TailCalls.scala
index 868ee4489d..49bca5364c 100644
--- a/src/compiler/scala/tools/nsc/transform/TailCalls.scala
+++ b/src/compiler/scala/tools/nsc/transform/TailCalls.scala
@@ -320,8 +320,13 @@ abstract class TailCalls extends Transform {
// the assumption is once we encounter a case, the remainder of the block will consist of cases
// the prologue may be empty, usually it is the valdef that stores the scrut
val (prologue, cases) = stats span (s => !s.isInstanceOf[LabelDef])
+ val transformedPrologue = noTailTransforms(prologue)
+ val transformedCases = transformTrees(cases)
+ val transformedStats =
+ if ((prologue eq transformedPrologue) && (cases eq transformedCases)) stats // allow reuse of `tree` if the subtransform was an identity
+ else transformedPrologue ++ transformedCases
treeCopy.Block(tree,
- noTailTransforms(prologue) ++ transformTrees(cases),
+ transformedStats,
transform(expr)
)