Skip to content

Commit 8530a2c

Browse files
committed
[String] Hand-increment loop variable for perf.
Hand-incrementing the loop variable allows us to skip overflow detection, and will permit more vectorization improvements in the future. For now, it gives us perf improvements in nano-benchmarks.
1 parent c0c530a commit 8530a2c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

stdlib/public/core/StringComparison.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,13 @@ private func _stringCompareSlow(
184184
private func _findDiffIdx(
185185
_ left: UnsafeBufferPointer<UInt8>, _ right: UnsafeBufferPointer<UInt8>
186186
) -> Int? {
187-
var count = Swift.min(left.count, right.count)
188-
for idx in 0..<count {
187+
let count = Swift.min(left.count, right.count)
188+
var idx = 0
189+
while idx < count {
189190
guard left[_unchecked: idx] == right[_unchecked: idx] else {
190191
return idx
191192
}
193+
idx &+= 1
192194
}
193195
return nil
194196
}

0 commit comments

Comments
 (0)