From d6cb47cbc4bc5468b42eda87a90c865728b84c6a Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 8 Oct 2014 11:28:10 +1000 Subject: 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. --- src/compiler/scala/tools/nsc/transform/TailCalls.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') 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) ) -- cgit v1.2.3