mirror of
https://github.com/apple/swift-collections
synced 2026-11-25 04:37:48 +00:00
Merge pull request #195 from lorentey/fix-bitset-shrinking-issue
[BitSet] Fix invariant violation in member subscript
This commit is contained in:
2 files changed
+8
-8
No files matched your search
@@ -70,7 +70,9 @@ extension BitSet {
|
||||
} else if member > _capacity {
|
||||
return
|
||||
}
|
||||
_update { handle in handle[member: member] = newValue }
|
||||
_updateThenShrink { handle, shrink in
|
||||
shrink = handle.update(member, to: newValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -189,13 +189,11 @@ extension BitSet._UnsafeHandle {
|
||||
return _mutableWords[index.word].remove(index.bit)
|
||||
}
|
||||
|
||||
subscript(member member: UInt) -> Bool {
|
||||
get { contains(member) }
|
||||
set {
|
||||
ensureMutable()
|
||||
let (w, b) = _BitPosition(member).split
|
||||
_mutableWords[w].update(b, to: newValue)
|
||||
}
|
||||
internal mutating func update(_ member: UInt, to newValue: Bool) -> Bool {
|
||||
ensureMutable()
|
||||
let (w, b) = _BitPosition(member).split
|
||||
_mutableWords[w].update(b, to: newValue)
|
||||
return w == _words.count &- 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user