Skip to content

Commit 2ba6cc9

Browse files
authored
Merge pull request #11157 from airspeedswift/stringprotocolify
[stdlib] Switch Int/Float inits + join to be on StringProtocol
2 parents 7b9d29e + 92bc5b7 commit 2ba6cc9

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

stdlib/public/core/FloatingPointParsing.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ extension ${Self} : LosslessStringConvertible {
123123
/// - Parameter text: The input string to convert to a `${Self}` instance. If
124124
/// `text` has invalid characters or is in an invalid format, the result
125125
/// is `nil`.
126-
public init?(_ text: String) {
126+
public init?<S: StringProtocol>(_ text: S) {
127127
let u16 = text.utf16
128128
func parseNTBS(_ chars: UnsafePointer<CChar>) -> (${Self}, Int) {
129129
var result: ${Self} = 0
@@ -133,7 +133,7 @@ extension ${Self} : LosslessStringConvertible {
133133
return (result, endPtr == nil ? 0 : endPtr! - chars)
134134
}
135135

136-
let (result, n) = text.withCString(parseNTBS)
136+
let (result, n) = text._ephemeralString.withCString(parseNTBS)
137137

138138
if n == 0 || n != u16.count
139139
|| u16.contains(where: { $0 > 127 || _isspace_clocale($0) }) {

stdlib/public/core/IntegerParsing.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ extension FixedWidthInteger {
131131
/// - radix: The radix, or base, to use for converting `text` to an integer
132132
/// value. `radix` must be in the range `2...36`. The default is 10.
133133
@_semantics("optimize.sil.specialize.generic.partial.never")
134-
public init?/*<S : StringProtocol>*/(_ text: String, radix: Int = 10) {
134+
public init?<S : StringProtocol>(_ text: S, radix: Int = 10) {
135135
_precondition(2...36 ~= radix, "Radix not in range 2...36")
136136
let r = Self(radix)
137-
let s = text// ._ephemeralString
137+
let s = text._ephemeralString
138138
defer { _fixLifetime(s) }
139139

140140
let c = s._core

stdlib/public/core/String.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ extension String {
873873
}
874874
}
875875

876-
extension Sequence where Element == String {
876+
extension Sequence where Element: StringProtocol {
877877

878878
/// Returns a new string by concatenating the elements of the sequence,
879879
/// adding the given separator between each element.
@@ -907,7 +907,7 @@ extension Sequence where Element == String {
907907
for chunk in self {
908908
// FIXME(performance): this code assumes UTF-16 in-memory representation.
909909
// It should be switched to low-level APIs.
910-
r += separatorSize + chunk.utf16.count
910+
r += separatorSize + chunk._ephemeralString.utf16.count
911911
}
912912
return r - separatorSize
913913
}
@@ -918,17 +918,17 @@ extension Sequence where Element == String {
918918

919919
if separatorSize == 0 {
920920
for x in self {
921-
result.append(x)
921+
result.append(x._ephemeralString)
922922
}
923923
return result
924924
}
925925

926926
var iter = makeIterator()
927927
if let first = iter.next() {
928-
result.append(first)
928+
result.append(first._ephemeralString)
929929
while let next = iter.next() {
930930
result.append(separator)
931-
result.append(next)
931+
result.append(next._ephemeralString)
932932
}
933933
}
934934

0 commit comments

Comments
 (0)