Skip to content

Commit 1b99845

Browse files
committed
Avoid hot closure creation in TreeAccumulator
1 parent 9149e6b commit 1b99845

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,12 @@ object Trees {
13751375
// Ties the knot of the traversal: call `foldOver(x, tree))` to dive in the `tree` node.
13761376
def apply(x: X, tree: Tree)(using Context): X
13771377

1378-
def apply(x: X, trees: Traversable[Tree])(using Context): X = trees.foldLeft(x)(apply)
1378+
def apply(x: X, trees: List[Tree])(using Context): X = trees match
1379+
case tree :: rest =>
1380+
apply(apply(x, tree), rest)
1381+
case Nil =>
1382+
x
1383+
13791384
def foldOver(x: X, tree: Tree)(using Context): X =
13801385
if (tree.source != ctx.source && tree.source.exists)
13811386
foldOver(x, tree)(using ctx.withSource(tree.source))

0 commit comments

Comments
 (0)