Skip to content

Commit ba59831

Browse files
committed
Add comment to func _icuMakeStringFromBytes_impl.
In response to: swiftlang#1296 (comment)
1 parent 5da8fc6 commit ba59831

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Sources/FoundationInternationalization/ICU/ICU+StringConverter.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ func _icuMakeStringFromBytes_impl(_ bytes: UnsafeBufferPointer<UInt8>, encoding:
178178
let pointer = bytes.baseAddress else {
179179
return nil
180180
}
181+
182+
// Since we want to avoid unnecessary copy here,
183+
// `bytes` is converted to `UnsafeMutableRawPointer`
184+
// because `Data(bytesNoCopy:count:deallocator:)` accepts only that type.
185+
// This operation is still safe,
186+
// as the pointer is just borrowed (not escaped, not mutated)
187+
// in `ICU.StringConverter.decode(data:) -> String?`.
188+
// In addition to that, `Data` is useful here
189+
// because it is `Sendable` (and has CoW behavior).
181190
let data = Data(
182191
bytesNoCopy: UnsafeMutableRawPointer(mutating: pointer),
183192
count: bytes.count,

0 commit comments

Comments
 (0)