Skip to content

Commit c5ce6be

Browse files
committed
Avoid closure creation in Thicket.span
1 parent 9f0dd66 commit c5ce6be

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,11 @@ object Trees {
846846
override def isEmpty: Boolean = trees.isEmpty
847847
override def toList: List[Tree[T]] = flatten(trees)
848848
override def toString: String = if (isEmpty) "EmptyTree" else "Thicket(" + trees.mkString(", ") + ")"
849-
override def span: Span = trees.foldLeft(NoSpan) ((span, t) => span union t.span)
849+
override def span: Span =
850+
def combine(s: Span, ts: List[Tree[T]]): Span = ts match
851+
case t :: ts1 => combine(s.union(t.span), ts1)
852+
case nil => s
853+
combine(NoSpan, trees)
850854

851855
override def withSpan(span: Span): this.type =
852856
mapElems(_.withSpan(span)).asInstanceOf[this.type]

0 commit comments

Comments
 (0)