Skip to content

Commit 8610bdf

Browse files
committed
[stdlib] String.unicodeScalars: Add a _modify accessor
This will eliminate unnecessary CoW copies when calling mutating Unicode scalar view methods directly through this property.
1 parent d588112 commit 8610bdf

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

stdlib/public/core/StringUnicodeScalarView.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,14 @@ extension String {
319319
public var unicodeScalars: UnicodeScalarView {
320320
@inline(__always) get { return UnicodeScalarView(_guts) }
321321
@inline(__always) set { _guts = newValue._guts }
322+
323+
@_alwaysEmitIntoClient @inline(__always) // 5.7
324+
_modify {
325+
var view = self.unicodeScalars
326+
self = ""
327+
defer { self._guts = view._guts }
328+
yield &view
329+
}
322330
}
323331
}
324332

0 commit comments

Comments
 (0)