We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
std::string
Swift.String
1 parent 739c719 commit 5d81136Copy full SHA for 5d81136
stdlib/public/Cxx/std/String.swift
@@ -20,11 +20,17 @@ extension std.string {
20
/// - Complexity: O(*n*), where *n* is the number of UTF-8 code units in the
21
/// Swift string.
22
public init(_ string: String) {
23
- self.init()
24
- let utf8 = string.utf8
25
- self.reserve(utf8.count)
26
- for char in utf8 {
27
- self.push_back(value_type(bitPattern: char))
+ if string.isContiguousUTF8 {
+ self = string.withCString(encodedAs: UTF8.self) { buffer in
+ Self(buffer, string.utf8.count, .init())
+ }
+ } else {
28
+ self.init()
29
+ let utf8 = string.utf8
30
+ self.reserve(utf8.count)
31
+ for char in utf8 {
32
+ self.push_back(value_type(bitPattern: char))
33
34
}
35
36
0 commit comments