Skip to content

Commit 7de462e

Browse files
authored
Merge pull request #286 from lorentey/silence-32bit-warning
[CollectionUtilities] Silence a warning on 32 bit platforms
2 parents 992e0f3 + 0c00220 commit 7de462e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Sources/_CollectionsUtilities/IntegerTricks/Integer rank.swift.gyb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ extension UInt {
4141
var shift: Self = 0
4242
var n = Self(truncatingIfNeeded: n)
4343

44-
if Self.bitWidth == 64 {
44+
if MemoryLayout<UInt>.size == 8 {
4545
let c32 = (self & 0xFFFFFFFF)._nonzeroBitCount
4646
if n >= c32 {
4747
shift &+= 32
4848
n &-= c32
4949
}
50+
} else {
51+
assert(MemoryLayout<Self>.size == 4, "Unknown platform")
5052
}
53+
5154
let c16 = ((self &>> shift) & 0xFFFF)._nonzeroBitCount
5255
if n >= c16 {
5356
shift &+= 16

Sources/_CollectionsUtilities/IntegerTricks/autogenerated/Integer rank.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,16 @@ extension UInt {
4747
var shift: Self = 0
4848
var n = Self(truncatingIfNeeded: n)
4949

50-
if Self.bitWidth == 64 {
50+
if MemoryLayout<UInt>.size == 8 {
5151
let c32 = (self & 0xFFFFFFFF)._nonzeroBitCount
5252
if n >= c32 {
5353
shift &+= 32
5454
n &-= c32
5555
}
56+
} else {
57+
assert(MemoryLayout<Self>.size == 4, "Unknown platform")
5658
}
59+
5760
let c16 = ((self &>> shift) & 0xFFFF)._nonzeroBitCount
5861
if n >= c16 {
5962
shift &+= 16
@@ -184,13 +187,16 @@ extension UInt {
184187
var shift: Self = 0
185188
var n = Self(truncatingIfNeeded: n)
186189

187-
if Self.bitWidth == 64 {
190+
if MemoryLayout<UInt>.size == 8 {
188191
let c32 = (self & 0xFFFFFFFF)._nonzeroBitCount
189192
if n >= c32 {
190193
shift &+= 32
191194
n &-= c32
192195
}
196+
} else {
197+
assert(MemoryLayout<Self>.size == 4, "Unknown platform")
193198
}
199+
194200
let c16 = ((self &>> shift) & 0xFFFF)._nonzeroBitCount
195201
if n >= c16 {
196202
shift &+= 16

0 commit comments

Comments
 (0)