Skip to content

Commit beb11be

Browse files
committed
Specialize String append to dispatch to more concrete methods
1 parent bbc9be6 commit beb11be

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

stdlib/public/core/StringRangeReplaceableCollection.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,19 @@ extension String: RangeReplaceableCollection {
144144
/// Appends the characters in the given sequence to the string.
145145
///
146146
/// - Parameter newElements: A sequence of characters.
147-
@inlinable // @specializable
147+
@_specialize(where S == String)
148+
@_specialize(where S == Substring)
149+
@_specialize(where S == Array<Character>)
148150
public mutating func append<S : Sequence>(contentsOf newElements: S)
149151
where S.Iterator.Element == Character {
152+
if let str = newElements as? String {
153+
self.append(str)
154+
return
155+
}
156+
if let substr = newElements as? Substring {
157+
self.append(contentsOf: substr)
158+
return
159+
}
150160
for c in newElements {
151161
self.append(c._str)
152162
}

0 commit comments

Comments
 (0)