File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
Sources/FoundationEssentials/String Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -99,11 +99,18 @@ extension String {
9999 // Put the BOM in, then copy the UTF16 bytes to the buffer after it.
100100 utf16Buffer [ 0 ] = bom
101101 let afterBOMBuffer = UnsafeMutableBufferPointer ( rebasing: utf16Buffer [ 1 ..< utf16Buffer. endIndex] )
102- self . _copyUTF16CodeUnits ( into: afterBOMBuffer, range: 0 ..< inputCount)
102+ if self . isContiguousUTF8 {
103+ self . _copyUTF16CodeUnits ( into: afterBOMBuffer, range: 0 ..< inputCount)
104+ } else {
105+ _ = afterBOMBuffer. initialize ( fromContentsOf: self . utf16)
106+ }
103107 } else {
104- self . _copyUTF16CodeUnits ( into: utf16Buffer, range: 0 ..< inputCount)
105- }
106-
108+ if self . isContiguousUTF8 {
109+ self . _copyUTF16CodeUnits ( into: utf16Buffer, range: 0 ..< inputCount)
110+ } else {
111+ _ = utf16Buffer. initialize ( fromContentsOf: self . utf16)
112+ }
113+ }
107114
108115 // If we need to swap endianness, we do it as a second pass over the data
109116 if swap {
You can’t perform that action at this time.
0 commit comments