Skip to content

Commit

Permalink
Make distinctRefs in ImportSuggestions use constant stackspace
Browse files Browse the repository at this point in the history
Fixes scala#12876 (hopefully)
  • Loading branch information
odersky committed Oct 3, 2021
1 parent 8c3e7a2 commit cded3d2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,14 @@ trait ImportSuggestions:
/** The `ref` parts of this list of pairs, discarding subsequent elements that
* have the same String part. Elements are sorted by their String parts.
*/
extension (refs: List[(TermRef, String)]) def distinctRefs(using Context): List[TermRef] = refs match
case (ref, str) :: refs1 =>
ref :: refs1.dropWhile(_._2 == str).distinctRefs
case Nil =>
Nil
extension (refs: List[(TermRef, String)]) def distinctRefs(using Context): List[TermRef] =
val buf = new mutable.ListBuffer[TermRef]
var last = ""
for (ref, str) <- refs do
if last != str then
buf += ref
last = str
buf.toList

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

0 comments on commit cded3d2

Please sign in to comment.