Skip to content

Commit e0ad2d5

Browse files
committed
Split up a couple expressions to work around slow type checking.
The type checker is particularly slow on these expressions. I've opened https://bugs.swift.org/browse/SR-5322 to investigate the type checker issue, but in the meantime it would be nice to speed up builds. This cuts more than a minute from my unoptimized asserts-enabled build.
1 parent 3c8d51e commit e0ad2d5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Foundation/NSCFString.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,19 @@ internal class _NSCFString : NSMutableString {
5959

6060
internal final class _NSCFConstantString : _NSCFString {
6161
internal var _ptr : UnsafePointer<UInt8> {
62-
let offset = MemoryLayout<OpaquePointer>.size + MemoryLayout<Int32>.size + MemoryLayout<Int32>.size + MemoryLayout<_CFInfo>.size
62+
// FIXME: Split expression as a work-around for slow type checking.
63+
let offTemp1 = MemoryLayout<OpaquePointer>.size + MemoryLayout<Int32>.size
64+
let offTemp2 = MemoryLayout<Int32>.size + MemoryLayout<_CFInfo>.size
65+
let offset = offTemp1 + offTemp2
6366
let ptr = Unmanaged.passUnretained(self).toOpaque()
6467
return ptr.load(fromByteOffset: offset, as: UnsafePointer<UInt8>.self)
6568
}
6669

6770
private var _lenOffset : Int {
68-
return MemoryLayout<OpaquePointer>.size + MemoryLayout<Int32>.size + MemoryLayout<Int32>.size + MemoryLayout<_CFInfo>.size + MemoryLayout<UnsafePointer<UInt8>>.size
71+
// FIXME: Split expression as a work-around for slow type checking.
72+
let offTemp1 = MemoryLayout<OpaquePointer>.size + MemoryLayout<Int32>.size
73+
let offTemp2 = MemoryLayout<Int32>.size + MemoryLayout<_CFInfo>.size
74+
return offTemp1 + offTemp2 + MemoryLayout<UnsafePointer<UInt8>>.size
6975
}
7076

7177
private var _lenPtr : UnsafeMutableRawPointer {

0 commit comments

Comments
 (0)