mirror of
https://github.com/apple/swift-algorithms
synced 2026-11-26 04:27:48 +00:00
Remove compilation bottleneck for Swift 5.3.2 builds (#147)
Benchmarks on Xcode 12.4 showed compiling / type checking StrideCollection.offsetBackward was the bottleneck for building the package. Replacing the ternary operator in that function with an explicit if/else removes the bottleneck.
This commit is contained in:
1 parent
2327673b0e
commit
50be2c8b3f
1 file changed
+9
-3
@@ -226,9 +226,15 @@ extension StrideCollection: Collection {
|
||||
offsetBy n: Int,
|
||||
limitedBy limit: Index
|
||||
) -> Index? {
|
||||
let distance = i == endIndex
|
||||
? -((base.count - 1) % stride + 1) + (n - 1) * -stride
|
||||
: n * -stride
|
||||
// We typically use the ternary operator but this significantly increases
|
||||
// compile times when using Swift 5.3.2
|
||||
// https://github.com/apple/swift-algorithms/issues/146
|
||||
let distance: Int
|
||||
if i == endIndex {
|
||||
distance = -((base.count - 1) % stride + 1) + (n - 1) * -stride
|
||||
} else {
|
||||
distance = n * -stride
|
||||
}
|
||||
return base.index(
|
||||
i.base,
|
||||
offsetBy: distance,
|
||||
|
||||
Reference in new issue
Block a user