Skip to content

Commit 8b790a6

Browse files
committed
Avoid hot closure creation in TreeAccumulator
1 parent f30279f commit 8b790a6

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
@@ -1384,7 +1384,12 @@ object Trees {
13841384
// Ties the knot of the traversal: call `foldOver(x, tree))` to dive in the `tree` node.
13851385
def apply(x: X, tree: Tree)(using Context): X
13861386

1387-
def apply(x: X, trees: Traversable[Tree])(using Context): X = trees.foldLeft(x)(apply)
1387+
def apply(x: X, trees: List[Tree])(using Context): X = trees match
1388+
case tree :: rest =>
1389+
apply(apply(x, tree), rest)
1390+
case Nil =>
1391+
x
1392+
13881393
def foldOver(x: X, tree: Tree)(using Context): X =
13891394
if (tree.source != ctx.source && tree.source.exists)
13901395
foldOver(x, tree)(using ctx.withSource(tree.source))

0 commit comments

Comments
 (0)