Skip to content

Commit 85862c1

Browse files
authored
(162310665) Guarantee specialization of String decomposition implementation (swiftlang#1701)
1 parent a49715d commit 85862c1

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

Sources/FoundationEssentials/String/String+Internals.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,20 @@ extension UnsafeBufferPointer {
262262
case illegalScalar
263263
case decodingError
264264
}
265-
265+
266+
@inline(__always) // Trivially forwarding and generic, inlining ensures calls are fully specialized
266267
fileprivate func _decomposedRebinding<T: UnicodeCodec, InputElement>(_ type: String._NormalizationType, as codec: T.Type, into buffer: UnsafeMutableBufferPointer<InputElement>, nullTerminated: Bool = false) throws -> Int {
267268
try self.withMemoryRebound(to: T.CodeUnit.self) { reboundSelf in
268269
try buffer.withMemoryRebound(to: Unicode.UTF8.CodeUnit.self) { reboundBuffer in
269270
try reboundSelf._decomposed(type, as: codec, into: reboundBuffer, nullTerminated: nullTerminated)
270271
}
271272
}
272273
}
273-
274+
275+
@specialized(where T == Unicode.UTF8)
276+
#if FOUNDATION_FRAMEWORK
277+
@specialized(where T == Unicode.UTF16)
278+
#endif
274279
fileprivate func _decomposed<T: UnicodeCodec>(_ type: String._NormalizationType, as codec: T.Type, into buffer: UnsafeMutableBufferPointer<UInt8>, nullTerminated: Bool = false) throws -> Int where Element == T.CodeUnit {
275280
let scalarSet = BuiltInUnicodeScalarSet(type: type.setType)
276281
var bufferIdx = 0

0 commit comments

Comments
 (0)