@@ -2460,13 +2460,16 @@ internal struct _BitMap {
2460
2460
internal let values: UnsafeMutablePointer<UInt>
2461
2461
internal let bitCount: Int
2462
2462
2463
- // Note: We use UInt here to get unsigned math (shifts).
2464
- internal static func wordIndex(_ i: UInt) -> UInt {
2465
- return i / UInt._sizeInBits
2463
+ internal static func wordIndex(_ i: Int) -> Int {
2464
+ // Note: We perform the operation on UInts to get faster unsigned math
2465
+ // (shifts).
2466
+ return Int(bitPattern: UInt(bitPattern: i) / UInt(UInt._sizeInBits))
2466
2467
}
2467
2468
2468
- internal static func bitIndex(_ i: UInt) -> UInt {
2469
- return i % UInt._sizeInBits
2469
+ internal static func bitIndex(_ i: Int) -> UInt {
2470
+ // Note: We perform the operation on UInts to get faster unsigned math
2471
+ // (shifts).
2472
+ return UInt(bitPattern: i) % UInt(UInt._sizeInBits)
2470
2473
}
2471
2474
2472
2475
internal static func wordsFor(_ bitCount: Int) -> Int {
@@ -2493,21 +2496,18 @@ internal struct _BitMap {
2493
2496
internal subscript(i: Int) -> Bool {
2494
2497
get {
2495
2498
_sanityCheck(i < Int(bitCount) && i >= 0, "index out of bounds")
2496
- let idx = UInt(i)
2497
- let word = values[Int(_BitMap.wordIndex(idx))]
2498
- let bit = word & (1 << _BitMap.bitIndex(idx))
2499
+ let word = values[_BitMap.wordIndex(i)]
2500
+ let bit = word & (1 << _BitMap.bitIndex(i))
2499
2501
return bit != 0
2500
2502
}
2501
2503
nonmutating set {
2502
2504
_sanityCheck(i < Int(bitCount) && i >= 0, "index out of bounds")
2503
- let idx = UInt (i)
2504
- let wordIdx = _BitMap.wordIndex(idx )
2505
+ let wordIdx = _BitMap.wordIndex (i)
2506
+ let bitMask = 1 << _BitMap.bitIndex(i )
2505
2507
if newValue {
2506
- values[Int(wordIdx)] =
2507
- values[Int(wordIdx)] | (1 << _BitMap.bitIndex(idx))
2508
+ values[wordIdx] = values[wordIdx] | bitMask
2508
2509
} else {
2509
- values[Int(wordIdx)] =
2510
- values[Int(wordIdx)] & ~(1 << _BitMap.bitIndex(idx))
2510
+ values[wordIdx] = values[wordIdx] & ~bitMask
2511
2511
}
2512
2512
}
2513
2513
}
0 commit comments