Skip to content

Commit 92bc5b7

Browse files
committed
Switch Int/Float inits + join to be on StringProtocol
1 parent 50f053a commit 92bc5b7

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
@@ -880,7 +880,7 @@ extension String {
880880
}
881881
}
882882

883-
extension Sequence where Element == String {
883+
extension Sequence where Element: StringProtocol {
884884

885885
/// Returns a new string by concatenating the elements of the sequence,
886886
/// adding the given separator between each element.
@@ -914,7 +914,7 @@ extension Sequence where Element == String {
914914
for chunk in self {
915915
// FIXME(performance): this code assumes UTF-16 in-memory representation.
916916
// It should be switched to low-level APIs.
917-
r += separatorSize + chunk.utf16.count
917+
r += separatorSize + chunk._ephemeralString.utf16.count
918918
}
919919
return r - separatorSize
920920
}
@@ -925,17 +925,17 @@ extension Sequence where Element == String {
925925

926926
if separatorSize == 0 {
927927
for x in self {
928-
result.append(x)
928+
result.append(x._ephemeralString)
929929
}
930930
return result
931931
}
932932

933933
var iter = makeIterator()
934934
if let first = iter.next() {
935-
result.append(first)
935+
result.append(first._ephemeralString)
936936
while let next = iter.next() {
937937
result.append(separator)
938-
result.append(next)
938+
result.append(next._ephemeralString)
939939
}
940940
}
941941

0 commit comments

Comments
 (0)