From 4d05b759b2857ac192f9ad4f09295408a89d8301 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Thu, 14 Oct 2021 19:03:30 -0600 Subject: [PATCH] [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. --- stdlib/public/core/UnsafeRawBufferPointer.swift.gyb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb b/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb index c01039cb7b9a6..4fec4b4e52936 100644 --- a/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb +++ b/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb @@ -161,7 +161,7 @@ extension Unsafe${Mutable}RawBufferPointer: Sequence { } let destinationAddress = destination.baseAddress._unsafelyUnwrappedUnchecked let d = UnsafeMutableRawPointer(destinationAddress) - let n = Swift.min(destination.count, self.count) + let n = Swift.min(destination.count, s.distance(to: e)) d.copyMemory(from: s, byteCount: n) return (Iterator(_position: s.advanced(by: n), _end: e), n) }