Skip to content

Commit 14f7799

Browse files
authored
Merge pull request #18302 from DougGregor/stdlib-type-checking-perf
[Standard library] Ascribe types to some literals to improve typecheck time
2 parents d9c6fcf + ee1713c commit 14f7799

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

stdlib/public/core/Hasher.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ internal struct _HasherTailBuffer {
9090
internal init(tail: UInt64, byteCount: UInt64) {
9191
// byteCount can be any value, but we only keep the lower 8 bits. (The
9292
// lower three bits specify the count of bytes stored in this buffer.)
93-
// FIXME: The "as UInt64" annotations here eliminate some exponential
93+
// FIXME: This should be a single expression, but it causes exponential
9494
// behavior in the expression type checker <rdar://problem/42672946>.
95-
_sanityCheck(tail & ~((1 as UInt64) << ((byteCount & (7 as UInt64))
96-
<< (3 as UInt64)) - (1 as UInt64)) == (0 as UInt64))
95+
let shiftedByteCount: UInt64 = ((byteCount & 7) << 3)
96+
let mask: UInt64 = (1 << shiftedByteCount - 1)
97+
_sanityCheck(tail & ~mask == 0)
9798
self.value = (byteCount &<< 56 | tail)
9899
}
99100

stdlib/public/core/UTF16.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ extension Unicode.UTF16 : Unicode.Encoding {
6060
return Unicode.Scalar(_unchecked: bits & 0xffff)
6161
}
6262
_sanityCheck(source._bitCount == 32)
63-
let value = 0x10000 + (bits >> 16 & 0x03ff | (bits & 0x03ff) << 10)
63+
let lower: UInt32 = bits >> 16 & 0x03ff
64+
let upper: UInt32 = (bits & 0x03ff) << 10
65+
let value = 0x10000 + (lower | upper)
6466
return Unicode.Scalar(_unchecked: value)
6567
}
6668

0 commit comments

Comments
 (0)