Skip to content

Commit 3cd25fc

Browse files
committed
Use HashSet to record seen items
Use HashSet to record seen items in type size and covering set computations.
1 parent 4127cee commit 3cd25fc

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5577,11 +5577,11 @@ object Types {
55775577
}
55785578

55795579
class TypeSizeAccumulator(using Context) extends TypeAccumulator[Int] {
5580-
val seen = new java.util.IdentityHashMap[Type, Type]
5580+
var seen = util.HashSet[Type](initialCapacity = 8)
55815581
def apply(n: Int, tp: Type): Int =
5582-
if (seen.get(tp) != null) n
5582+
if seen.contains(tp) then n
55835583
else {
5584-
seen.put(tp, tp)
5584+
seen += tp
55855585
tp match {
55865586
case tp: AppliedType =>
55875587
foldOver(n + 1, tp)
@@ -5598,11 +5598,11 @@ object Types {
55985598
}
55995599

56005600
class CoveringSetAccumulator(using Context) extends TypeAccumulator[Set[Symbol]] {
5601-
val seen = new java.util.IdentityHashMap[Type, Type]
5601+
var seen = util.HashSet[Type](initialCapacity = 8)
56025602
def apply(cs: Set[Symbol], tp: Type): Set[Symbol] =
5603-
if (seen.get(tp) != null) cs
5603+
if seen.contains(tp) then cs
56045604
else {
5605-
seen.put(tp, tp)
5605+
seen += tp
56065606
tp match {
56075607
case tp if tp.isTopType || tp.isBottomType =>
56085608
cs

compiler/src/dotty/tools/dotc/util/LinearSet.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package dotty.tools.dotc.util
22
import collection.immutable
33

4-
/** A linear identity set is a set that uses `eq` as the underlying
5-
* equality where after a `+` the previous set value cannot be used anymore.
6-
* The set is implemented as an immutable set for
7-
* sizes <= 4 and as a HashSet for larger sizes.
4+
/** A linear set is a set here after a `+` the previous set value cannot be
5+
* used anymore. The set is implemented as an immutable set for sizes <= 4
6+
* and as a HashSet for larger sizes.
87
*/
98
opaque type LinearSet[Elem >: Null <: AnyRef] =
109
immutable.Set[Elem] | HashSet[Elem]

0 commit comments

Comments
 (0)