Skip to content

Commit 73b5666

Browse files
committed
Avoid closure creation in Thicket.span
1 parent 6abff2a commit 73b5666

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
@@ -855,7 +855,11 @@ object Trees {
855855
override def isEmpty: Boolean = trees.isEmpty
856856
override def toList: List[Tree[T]] = flatten(trees)
857857
override def toString: String = if (isEmpty) "EmptyTree" else "Thicket(" + trees.mkString(", ") + ")"
858-
override def span: Span = trees.foldLeft(NoSpan) ((span, t) => span union t.span)
858+
override def span: Span =
859+
def combine(s: Span, ts: List[Tree[T]]): Span = ts match
860+
case t :: ts1 => combine(s.union(t.span), ts1)
861+
case nil => s
862+
combine(NoSpan, trees)
859863

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

0 commit comments

Comments
 (0)