@@ -98,11 +98,20 @@ public struct HTTPResponse: Sendable, Hashable {
98
98
}
99
99
100
100
var fieldValue : String {
101
- String ( [
102
- Character ( Unicode . Scalar ( UInt8 ( self . code / 100 ) + 48 ) ) ,
103
- Character ( Unicode . Scalar ( UInt8 ( ( self . code / 10 ) % 10 ) + 48 ) ) ,
104
- Character ( Unicode . Scalar ( UInt8 ( self . code % 10 ) + 48 ) ) ,
105
- ] )
101
+ if #available( macOS 11 . 0 , iOS 14 . 0 , watchOS 7 . 0 , tvOS 14 . 0 , * ) {
102
+ return String ( unsafeUninitializedCapacity: 3 ) { buffer in
103
+ buffer [ 0 ] = UInt8 ( self . code / 100 ) + 48
104
+ buffer [ 1 ] = UInt8 ( ( self . code / 10 ) % 10 ) + 48
105
+ buffer [ 2 ] = UInt8 ( self . code % 10 ) + 48
106
+ return 3
107
+ }
108
+ } else {
109
+ return String ( [
110
+ Character ( Unicode . Scalar ( UInt8 ( self . code / 100 ) + 48 ) ) ,
111
+ Character ( Unicode . Scalar ( UInt8 ( ( self . code / 10 ) % 10 ) + 48 ) ) ,
112
+ Character ( Unicode . Scalar ( UInt8 ( self . code % 10 ) + 48 ) ) ,
113
+ ] )
114
+ }
106
115
}
107
116
108
117
static func isValidStatus( _ status: String ) -> Bool {
@@ -149,7 +158,11 @@ public struct HTTPResponse: Sendable, Hashable {
149
158
/// phrase.
150
159
public var status : Status {
151
160
get {
152
- Status ( uncheckedCode: Int ( self . pseudoHeaderFields. status. rawValue. _storage) !, reasonPhrase: self . reasonPhrase)
161
+ var codeIterator = self . pseudoHeaderFields. status. rawValue. _storage. utf8. makeIterator ( )
162
+ let code = Int ( codeIterator. next ( ) ! - 48 ) * 100 +
163
+ Int( codeIterator. next ( ) ! - 48 ) * 10 +
164
+ Int( codeIterator. next ( ) ! - 48 )
165
+ return Status ( uncheckedCode: code, reasonPhrase: self . reasonPhrase)
153
166
}
154
167
set {
155
168
self . pseudoHeaderFields. status. rawValue = ISOLatin1String ( unchecked: newValue. fieldValue)
0 commit comments