Skip to content

Commit 45a07ab

Browse files
committed
replace as with specializingCast
1 parent 38659e6 commit 45a07ab

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

Sources/FoundationEssentials/JSON/JSONEncoder.swift

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,38 +1247,37 @@ private extension __JSONEncoder {
12471247
}
12481248

12491249
func _asDirectArrayEncoding<T: Encodable>(_ value: T, for additionalKey: (some CodingKey)? = _CodingKey?.none) -> _JSONDirectArrayEncodable? {
1250-
switch value {
1251-
case let array as [Int8]:
1252-
array
1253-
case let array as [Int16]:
1254-
array
1255-
case let array as [Int32]:
1250+
return if let array = _specializingCast(array, to: [Int8].self) {
12561251
array
1257-
case let array as [Int64]:
1252+
} else if let array = _specializingCast(array, to: [Int16].self) {
12581253
array
1259-
case let array as [Int128]:
1254+
} else if let array = _specializingCast(array, to: [Int32].self) {
12601255
array
1261-
case let array as [Int]:
1256+
} else if let array = _specializingCast(array, to: [Int64].self) {
12621257
array
1263-
case let array as [UInt8]:
1258+
} else if let array = _specializingCast(array, to: [Int128].self) {
12641259
array
1265-
case let array as [UInt16]:
1260+
} else if let array = _specializingCast(array, to: [Int].self) {
12661261
array
1267-
case let array as [UInt32]:
1262+
} else if let array = _specializingCast(array, to: [UInt8].self) {
12681263
array
1269-
case let array as [UInt64]:
1264+
} else if let array = _specializingCast(array, to: [UInt16].self) {
12701265
array
1271-
case let array as [UInt128]:
1266+
} else if let array = _specializingCast(array, to: [UInt32].self) {
12721267
array
1273-
case let array as [UInt]:
1268+
} else if let array = _specializingCast(array, to: [UInt64].self) {
12741269
array
1275-
case let array as [String]:
1270+
} else if let array = _specializingCast(array, to: [UInt128].self) {
12761271
array
1277-
case let array as [Float]:
1272+
} else if let array = _specializingCast(array, to: [UInt].self) {
12781273
array
1279-
case let array as [Double]:
1274+
} else if let array = _specializingCast(array, to: [String].self) {
12801275
array
1281-
default:
1276+
} else if let array = _specializingCast(array, to: [Float].self) {
1277+
array
1278+
} else if let array = _specializingCast(array, to: [Double].self) {
1279+
array
1280+
} else {
12821281
nil
12831282
}
12841283
}

0 commit comments

Comments
 (0)