Skip to content

Commit d5e88d9

Browse files
committed
[cxx-interop][overlay] Revert memcpy string init approach.
For some reason this isn't working, so I reverted to the previous approach. We can try to re-visit this in the future for a potential perf improvement.
1 parent e3563ef commit d5e88d9

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

stdlib/public/Cxx/std/String.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212

1313
extension std.string {
1414
public init(_ string: String) {
15-
let count = string.count
16-
self.init(count, value_type(0))
17-
var string = string
18-
string.withUTF8 {
19-
memcpy(UnsafeMutableRawPointer(mutating: UnsafeRawPointer(__dataUnsafe()!)),
20-
UnsafeMutableRawPointer(mutating: $0.baseAddress), count)
15+
self.init()
16+
for char in string.utf8 {
17+
self.push_back(value_type(char))
2118
}
2219
}
2320
}

0 commit comments

Comments
 (0)