Skip to content

Commit c75a555

Browse files
committed
Drop bounds on HashSet entry type
1 parent abeb4e3 commit c75a555

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object HashSet:
1919
* However, a table of size up to DenseLimit will be re-sized only
2020
* once the number of elements reaches the table's size.
2121
*/
22-
class HashSet[T >: Null <: AnyRef](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends MutableSet[T] {
22+
class HashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends MutableSet[T] {
2323
import HashSet.DenseLimit
2424

2525
private var used: Int = _
@@ -65,8 +65,9 @@ class HashSet[T >: Null <: AnyRef](initialCapacity: Int = 8, capacityMultiple: I
6565
index(idx + 1)
6666

6767
protected def entryAt(idx: Int) = table(idx).asInstanceOf[T]
68+
protected def setEntry(idx: Int, x: T) = table(idx) = x.asInstanceOf[AnyRef]
6869

69-
def lookup(x: T): T =
70+
def lookup(x: T): T | Null =
7071
Stats.record(statsItem("lookup"))
7172
var idx = firstIndex(x)
7273
var e = entryAt(idx)
@@ -79,7 +80,7 @@ class HashSet[T >: Null <: AnyRef](initialCapacity: Int = 8, capacityMultiple: I
7980
/** Add entry at `x` at index `idx` */
8081
protected def addEntryAt(idx: Int, x: T): T =
8182
Stats.record(statsItem("addEntryAt"))
82-
table(idx) = x
83+
setEntry(idx, x)
8384
used += 1
8485
if used > limit then growTable()
8586
x
@@ -112,7 +113,7 @@ class HashSet[T >: Null <: AnyRef](initialCapacity: Int = 8, capacityMultiple: I
112113
|| index(hole - index(hash(e))) < limit
113114
// hash(k) is then logically at or before hole; can be moved forward to fill hole
114115
then
115-
table(hole) = e
116+
setEntry(hole, e)
116117
hole = idx
117118
table(hole) = null
118119
used -= 1
@@ -127,7 +128,7 @@ class HashSet[T >: Null <: AnyRef](initialCapacity: Int = 8, capacityMultiple: I
127128
while e != null do
128129
idx = nextIndex(idx)
129130
e = entryAt(idx)
130-
table(idx) = x
131+
setEntry(idx, x)
131132

132133
def copyFrom(oldTable: Array[AnyRef]): Unit =
133134
if isDense then

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package dotty.tools.dotc.util
22

33
/** A common class for lightweight mutable sets.
44
*/
5-
abstract class MutableSet[T >: Null] {
5+
abstract class MutableSet[T] {
66

77
/** The entry in the set such that `isEqual(x, entry)`, or else `null`. */
8-
def lookup(x: T): T /* | Null */
8+
def lookup(x: T): T | Null
99

1010
/** Add element `x` to the set */
1111
def +=(x: T): Unit

0 commit comments

Comments
 (0)