Skip to content

Commit d74b183

Browse files
committed
stdlib: Dictionary, Set: stop overallocating the bitmap
The 'sizeInWords(forSizeInBits:)' function was supposed to return the size in words, but returned the size in bits, overallocating the bitmap by a factor of 32 or 64, depending on the platform.
1 parent cb5a225 commit d74b183

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

stdlib/public/core/UnsafeBitMap.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct _UnsafeBitMap {
3535

3636
public // @testable
3737
static func sizeInWords(forSizeInBits bitCount: Int) -> Int {
38-
return bitCount + Int._sizeInBytes - 1 / Int._sizeInBytes
38+
return (bitCount + Int._sizeInBits - 1) / Int._sizeInBits
3939
}
4040

4141
public // @testable

validation-test/stdlib/UnsafeBitMap.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ UnsafeBitMapTests.test("wordIndex(_:), bitIndex(_:)") {
4141
#endif
4242
}
4343

44-
UnsafeBitMapTests.test("sizeInWords(forSizeInBits:)")
45-
.xfail(.always("the API is buggy")).code {
44+
UnsafeBitMapTests.test("sizeInWords(forSizeInBits:)") {
4645
expectEqual(0, _UnsafeBitMap.sizeInWords(forSizeInBits: 0))
4746
#if arch(i386) || arch(arm)
4847
for i in 1...32 {

0 commit comments

Comments
 (0)