@@ -11,9 +11,6 @@ public struct ObjectData {
11
11
public let _transformer : any _ObjectData_Transformer
12
12
public let _rawData : [ String : AnyHashable ]
13
13
14
- @usableFromInline internal static let _boolTrue = AnyHashable ( true )
15
- @usableFromInline internal static let _boolFalse = AnyHashable ( false )
16
-
17
14
public init (
18
15
_transformer: any _ObjectData_Transformer ,
19
16
_rawData: [ String : AnyHashable ]
@@ -29,7 +26,7 @@ public struct ObjectData {
29
26
// This check is based on AnyHashable using a canonical representation of the type-erased value so
30
27
// instances wrapping the same value of any type compare as equal. Therefore while Int(1) and Int(0)
31
28
// might be representable as Bool they will never equal Bool(true) nor Bool(false).
32
- if let boolVal = value as? Bool , ( value == Self . _boolTrue || value == Self . _boolFalse ) {
29
+ if let boolVal = value as? Bool , value. isCanonicalBool {
33
30
value = boolVal
34
31
35
32
// Cast to `Int` to ensure we always use `Int` vs `Int32` or `Int64` for consistency and ScalarType casting
@@ -72,17 +69,17 @@ public struct ListData {
72
69
@inlinable public subscript( _ key: Int ) -> ( any ScalarType ) ? {
73
70
var value : AnyHashable = _rawData [ key]
74
71
75
- // Attempting cast to `Int` to ensure we always use `Int` vs `Int32` or `Int64` for consistency and ScalarType casting,
76
- // also need to attempt `Bool` cast first to ensure a bool doesn't get inadvertently converted to ` Int`
77
- switch value {
78
- case let boolVal as Bool :
72
+ // This check is based on AnyHashable using a canonical representation of the type-erased value so
73
+ // instances wrapping the same value of any type compare as equal. Therefore while Int(1) and Int(0)
74
+ // might be representable as Bool they will never equal Bool(true) nor Bool(false).
75
+ if let boolVal = value as? Bool , value . isCanonicalBool {
79
76
value = boolVal
80
- case let intVal as Int :
81
- value = intVal
82
- default :
83
- break
77
+
78
+ // Cast to `Int` to ensure we always use `Int` vs `Int32` or `Int64` for consistency and ScalarType casting
79
+ } else if let intValue = value as? Int {
80
+ value = intValue
84
81
}
85
-
82
+
86
83
return _transformer. transform ( value)
87
84
}
88
85
@@ -96,3 +93,12 @@ public struct ListData {
96
93
return _transformer. transform ( _rawData [ key] )
97
94
}
98
95
}
96
+
97
+ extension AnyHashable {
98
+ fileprivate static let boolTrue = AnyHashable ( true )
99
+ fileprivate static let boolFalse = AnyHashable ( false )
100
+
101
+ @usableFromInline var isCanonicalBool : Bool {
102
+ self == Self . boolTrue || self == Self . boolFalse
103
+ }
104
+ }
0 commit comments