mirror of
https://github.com/apple/swift-collections
synced 2026-11-28 05:04:21 +00:00
[CollectionUtilities] Silence a warning on 32 bit platforms
It turns out `UInt.bitWidth` is getting too eagerly inlined, so conditions based on it trigger spurious “code will never be executed” warnings. Silence those by switching to looking at `MemoryLayout<UInt>`, which doesn’t get turned into a constant *that* early.
This commit is contained in:
2 files changed
+12
-3
No files matched your search
@@ -41,13 +41,16 @@ extension UInt {
|
||||
var shift: Self = 0
|
||||
var n = Self(truncatingIfNeeded: n)
|
||||
|
||||
if Self.bitWidth == 64 {
|
||||
if MemoryLayout<UInt>.size == 8 {
|
||||
let c32 = (self & 0xFFFFFFFF)._nonzeroBitCount
|
||||
if n >= c32 {
|
||||
shift &+= 32
|
||||
n &-= c32
|
||||
}
|
||||
} else {
|
||||
assert(MemoryLayout<Self>.size == 4, "Unknown platform")
|
||||
}
|
||||
|
||||
let c16 = ((self &>> shift) & 0xFFFF)._nonzeroBitCount
|
||||
if n >= c16 {
|
||||
shift &+= 16
|
||||
|
||||
@@ -47,13 +47,16 @@ extension UInt {
|
||||
var shift: Self = 0
|
||||
var n = Self(truncatingIfNeeded: n)
|
||||
|
||||
if Self.bitWidth == 64 {
|
||||
if MemoryLayout<UInt>.size == 8 {
|
||||
let c32 = (self & 0xFFFFFFFF)._nonzeroBitCount
|
||||
if n >= c32 {
|
||||
shift &+= 32
|
||||
n &-= c32
|
||||
}
|
||||
} else {
|
||||
assert(MemoryLayout<Self>.size == 4, "Unknown platform")
|
||||
}
|
||||
|
||||
let c16 = ((self &>> shift) & 0xFFFF)._nonzeroBitCount
|
||||
if n >= c16 {
|
||||
shift &+= 16
|
||||
@@ -184,13 +187,16 @@ extension UInt {
|
||||
var shift: Self = 0
|
||||
var n = Self(truncatingIfNeeded: n)
|
||||
|
||||
if Self.bitWidth == 64 {
|
||||
if MemoryLayout<UInt>.size == 8 {
|
||||
let c32 = (self & 0xFFFFFFFF)._nonzeroBitCount
|
||||
if n >= c32 {
|
||||
shift &+= 32
|
||||
n &-= c32
|
||||
}
|
||||
} else {
|
||||
assert(MemoryLayout<Self>.size == 4, "Unknown platform")
|
||||
}
|
||||
|
||||
let c16 = ((self &>> shift) & 0xFFFF)._nonzeroBitCount
|
||||
if n >= c16 {
|
||||
shift &+= 16
|
||||
|
||||
Reference in new issue
Block a user