Skip to content

Commit 03b5324

Browse files
committed
Implement HashSet.-= in terms of remove, not the other way around.
1 parent daa4643 commit 03b5324

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class HashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends Mu
9797

9898
def +=(x: T): Unit = put(x)
9999

100-
def -= (x: T): Unit =
100+
def remove(x: T): Boolean =
101101
Stats.record(statsItem("remove"))
102102
var idx = firstIndex(x)
103103
var e = entryAt(idx)
@@ -117,16 +117,13 @@ class HashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends Mu
117117
hole = idx
118118
table(hole) = null
119119
used -= 1
120-
return
120+
return true
121121
idx = nextIndex(idx)
122122
e = entryAt(idx)
123+
false
123124

124-
def remove(x: T): Boolean =
125-
if contains(x) then
126-
this -= x
127-
true
128-
else
129-
false
125+
def -=(x: T): Unit =
126+
remove(x)
130127

131128
private def addOld(x: T) =
132129
Stats.record(statsItem("re-enter"))

0 commit comments

Comments
 (0)