Skip to content

Commit 1b518b1

Browse files
authored
Merge pull request #3942 from dotty-staging/opt/splitter-alloc
Splitter: Avoid unnecessary allocations (20% fewer Apply nodes)
2 parents 0591d23 + 575c2da commit 1b518b1

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

compiler/src/dotty/tools/dotc/transform/Splitter.scala

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,22 @@ class Splitter extends MiniPhase {
2323
recur(tree.fun)
2424
}
2525

26+
private def needsDistribution(fun: Tree) = fun match {
27+
case _: Block | _: If => true
28+
case _ => false
29+
}
30+
2631
override def transformTypeApply(tree: TypeApply)(implicit ctx: Context) =
27-
distribute(tree, typeApply)
32+
if (needsDistribution(tree.fun))
33+
distribute(tree, typeApply)
34+
else
35+
tree
2836

2937
override def transformApply(tree: Apply)(implicit ctx: Context) =
30-
distribute(tree, apply)
38+
if (needsDistribution(tree.fun))
39+
distribute(tree, apply)
40+
else
41+
tree
3142

3243
private val typeApply = (fn: Tree, args: List[Tree]) => (ctx: Context) => TypeApply(fn, args)(ctx)
3344
private val apply = (fn: Tree, args: List[Tree]) => (ctx: Context) => Apply(fn, args)(ctx)

0 commit comments

Comments
 (0)