Skip to content

Commit 874cd33

Browse files
committed
[stdlib] avoid work when source and destination are the same
1 parent 04f1cde commit 874cd33

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

stdlib/public/core/UnsafePointer.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,8 @@ public struct UnsafeMutablePointer<Pointee>: _Pointer {
843843
/// `moveInitialize(from:count:)`, the region is initialized and the memory
844844
/// region `source..<(source + count)` is uninitialized.
845845
///
846+
/// - Note: Returns without performing work if `self` and `source` are equal.
847+
///
846848
/// - Parameters:
847849
/// - source: A pointer to the values to copy. The memory region
848850
/// `source..<(source + count)` must be initialized. The memory regions
@@ -864,7 +866,7 @@ public struct UnsafeMutablePointer<Pointee>: _Pointer {
864866
// (self + i).initialize(to: (source + i).move())
865867
// }
866868
}
867-
else {
869+
else if self != source {
868870
// initialize backward from a non-following overlapping range.
869871
Builtin.takeArrayBackToFront(
870872
Pointee.self, self._rawValue, source._rawValue, count._builtinWordValue)

0 commit comments

Comments
 (0)