Skip to content

Commit 85d444e

Browse files
authored
Merge pull request #13667 from dotty-staging/fix-12876
Make `distinctRefs` in ImportSuggestions use constant stackspace
2 parents d4ba729 + cded3d2 commit 85d444e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,14 @@ trait ImportSuggestions:
273273
/** The `ref` parts of this list of pairs, discarding subsequent elements that
274274
* have the same String part. Elements are sorted by their String parts.
275275
*/
276-
extension (refs: List[(TermRef, String)]) def distinctRefs(using Context): List[TermRef] = refs match
277-
case (ref, str) :: refs1 =>
278-
ref :: refs1.dropWhile(_._2 == str).distinctRefs
279-
case Nil =>
280-
Nil
276+
extension (refs: List[(TermRef, String)]) def distinctRefs(using Context): List[TermRef] =
277+
val buf = new mutable.ListBuffer[TermRef]
278+
var last = ""
279+
for (ref, str) <- refs do
280+
if last != str then
281+
buf += ref
282+
last = str
283+
buf.toList
281284

282285
/** The best `n` references in `refs`, according to `compare`
283286
* `compare` is a partial order. If there's a tie, we take elements

0 commit comments

Comments
 (0)