Skip to content

Commit a5fdf15

Browse files
authored
Merge pull request #72268 from apple/egorzhdan/std-string-reserve
[cxx-interop] Faster `std::string` initialization from String
2 parents bf58b03 + 4513ca2 commit a5fdf15

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

stdlib/public/Cxx/std/String.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ extension std.string {
2121
/// Swift string.
2222
public init(_ string: String) {
2323
self.init()
24-
for char in string.utf8 {
24+
let utf8 = string.utf8
25+
self.reserve(utf8.count)
26+
for char in utf8 {
2527
self.push_back(value_type(bitPattern: char))
2628
}
2729
}

0 commit comments

Comments
 (0)