Skip to content

Commit 076bd42

Browse files
committed
ConvenienceCopyable.copy optimization: avoid excessive copying
Test case: CreateNewValue() .copy(\.foo, baz) .copy(\.bar, duh) Expected: 0 copies Actual: 2 copies inside ConvenienceCopyable.copy
1 parent 3379727 commit 076bd42

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
public protocol ConvenienceCopyable {}
22

33
extension ConvenienceCopyable {
4-
public func copy<T>(_ key: WritableKeyPath<Self, T>, _ value: T) -> Self {
5-
var copy = self
6-
copy[keyPath: key] = value
7-
return copy
4+
public consuming func copy<T>(_ key: WritableKeyPath<Self, T>, _ value: T) -> Self {
5+
self[keyPath: key] = value
6+
return self
87
}
98
}

0 commit comments

Comments
 (0)