Skip to content

Commit

Permalink
Avoid hot closure creation in TreeAccumulator
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Jul 23, 2020
1 parent f30279f commit 8b790a6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,12 @@ object Trees {
// Ties the knot of the traversal: call `foldOver(x, tree))` to dive in the `tree` node.
def apply(x: X, tree: Tree)(using Context): X

def apply(x: X, trees: Traversable[Tree])(using Context): X = trees.foldLeft(x)(apply)
def apply(x: X, trees: List[Tree])(using Context): X = trees match
case tree :: rest =>
apply(apply(x, tree), rest)
case Nil =>
x

def foldOver(x: X, tree: Tree)(using Context): X =
if (tree.source != ctx.source && tree.source.exists)
foldOver(x, tree)(using ctx.withSource(tree.source))
Expand Down

0 comments on commit 8b790a6

Please sign in to comment.