Skip to content

Commit 4d05b75

Browse files
committed
[stdlib] a minor optimization
We have already done the hard work of unwrapping the optionals that represent the first and last pointer, and calling `self.count` does it all over again. Use the distance between the unwrapped pointers instead.
1 parent c2a7939 commit 4d05b75

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

stdlib/public/core/UnsafeRawBufferPointer.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ extension Unsafe${Mutable}RawBufferPointer: Sequence {
161161
}
162162
let destinationAddress = destination.baseAddress._unsafelyUnwrappedUnchecked
163163
let d = UnsafeMutableRawPointer(destinationAddress)
164-
let n = Swift.min(destination.count, self.count)
164+
let n = Swift.min(destination.count, s.distance(to: e))
165165
d.copyMemory(from: s, byteCount: n)
166166
return (Iterator(_position: s.advanced(by: n), _end: e), n)
167167
}

0 commit comments

Comments
 (0)