Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit 866e85e

Browse files
committed
Make == to use their hashValue
1 parent 9ab024b commit 866e85e

File tree

3 files changed

+12
-131
lines changed

3 files changed

+12
-131
lines changed

Sources/AnyCodable/AnyCodable.swift

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,6 @@
2121

2222
extension AnyCodable: _AnyEncodable, _AnyDecodable {}
2323

24-
extension AnyCodable: Equatable {
25-
public static func == (lhs: AnyCodable, rhs: AnyCodable) -> Bool {
26-
switch (lhs.value, rhs.value) {
27-
case is (Void, Void):
28-
return true
29-
case let (lhs as Bool, rhs as Bool):
30-
return lhs == rhs
31-
case let (lhs as Int, rhs as Int):
32-
return lhs == rhs
33-
case let (lhs as Int8, rhs as Int8):
34-
return lhs == rhs
35-
case let (lhs as Int16, rhs as Int16):
36-
return lhs == rhs
37-
case let (lhs as Int32, rhs as Int32):
38-
return lhs == rhs
39-
case let (lhs as Int64, rhs as Int64):
40-
return lhs == rhs
41-
case let (lhs as UInt, rhs as UInt):
42-
return lhs == rhs
43-
case let (lhs as UInt8, rhs as UInt8):
44-
return lhs == rhs
45-
case let (lhs as UInt16, rhs as UInt16):
46-
return lhs == rhs
47-
case let (lhs as UInt32, rhs as UInt32):
48-
return lhs == rhs
49-
case let (lhs as UInt64, rhs as UInt64):
50-
return lhs == rhs
51-
case let (lhs as Float, rhs as Float):
52-
return lhs == rhs
53-
case let (lhs as Double, rhs as Double):
54-
return lhs == rhs
55-
case let (lhs as String, rhs as String):
56-
return lhs == rhs
57-
case let (lhs as [String: AnyCodable], rhs as [String: AnyCodable]):
58-
return lhs == rhs
59-
case let (lhs as [AnyCodable], rhs as [AnyCodable]):
60-
return lhs == rhs
61-
default:
62-
return false
63-
}
64-
}
65-
}
66-
6724
extension AnyCodable: CustomStringConvertible {
6825
public var description: String {
6926
switch value {
@@ -136,4 +93,8 @@ extension AnyCodable: Hashable {
13693
break
13794
}
13895
}
96+
97+
public static func ==(lhs: AnyCodable, rhs: AnyCodable) -> Bool {
98+
return lhs.hashValue == rhs.hashValue
99+
}
139100
}

Sources/AnyCodable/AnyDecodable.swift

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -77,51 +77,6 @@ extension _AnyDecodable {
7777
}
7878
}
7979

80-
extension AnyDecodable: Equatable {
81-
public static func == (lhs: AnyDecodable, rhs: AnyDecodable) -> Bool {
82-
switch (lhs.value, rhs.value) {
83-
#if canImport(Foundation)
84-
case is (NSNull, NSNull), is (Void, Void):
85-
return true
86-
#endif
87-
case let (lhs as Bool, rhs as Bool):
88-
return lhs == rhs
89-
case let (lhs as Int, rhs as Int):
90-
return lhs == rhs
91-
case let (lhs as Int8, rhs as Int8):
92-
return lhs == rhs
93-
case let (lhs as Int16, rhs as Int16):
94-
return lhs == rhs
95-
case let (lhs as Int32, rhs as Int32):
96-
return lhs == rhs
97-
case let (lhs as Int64, rhs as Int64):
98-
return lhs == rhs
99-
case let (lhs as UInt, rhs as UInt):
100-
return lhs == rhs
101-
case let (lhs as UInt8, rhs as UInt8):
102-
return lhs == rhs
103-
case let (lhs as UInt16, rhs as UInt16):
104-
return lhs == rhs
105-
case let (lhs as UInt32, rhs as UInt32):
106-
return lhs == rhs
107-
case let (lhs as UInt64, rhs as UInt64):
108-
return lhs == rhs
109-
case let (lhs as Float, rhs as Float):
110-
return lhs == rhs
111-
case let (lhs as Double, rhs as Double):
112-
return lhs == rhs
113-
case let (lhs as String, rhs as String):
114-
return lhs == rhs
115-
case let (lhs as [String: AnyDecodable], rhs as [String: AnyDecodable]):
116-
return lhs == rhs
117-
case let (lhs as [AnyDecodable], rhs as [AnyDecodable]):
118-
return lhs == rhs
119-
default:
120-
return false
121-
}
122-
}
123-
}
124-
12580
extension AnyDecodable: CustomStringConvertible {
12681
public var description: String {
12782
switch value {
@@ -185,4 +140,8 @@ extension AnyDecodable: Hashable {
185140
break
186141
}
187142
}
143+
144+
public static func ==(lhs: AnyDecodable, rhs: AnyDecodable) -> Bool {
145+
return lhs.hashValue == rhs.hashValue
146+
}
188147
}

Sources/AnyCodable/AnyEncodable.swift

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -137,49 +137,6 @@ extension _AnyEncodable {
137137
#endif
138138
}
139139

140-
extension AnyEncodable: Equatable {
141-
public static func == (lhs: AnyEncodable, rhs: AnyEncodable) -> Bool {
142-
switch (lhs.value, rhs.value) {
143-
case is (Void, Void):
144-
return true
145-
case let (lhs as Bool, rhs as Bool):
146-
return lhs == rhs
147-
case let (lhs as Int, rhs as Int):
148-
return lhs == rhs
149-
case let (lhs as Int8, rhs as Int8):
150-
return lhs == rhs
151-
case let (lhs as Int16, rhs as Int16):
152-
return lhs == rhs
153-
case let (lhs as Int32, rhs as Int32):
154-
return lhs == rhs
155-
case let (lhs as Int64, rhs as Int64):
156-
return lhs == rhs
157-
case let (lhs as UInt, rhs as UInt):
158-
return lhs == rhs
159-
case let (lhs as UInt8, rhs as UInt8):
160-
return lhs == rhs
161-
case let (lhs as UInt16, rhs as UInt16):
162-
return lhs == rhs
163-
case let (lhs as UInt32, rhs as UInt32):
164-
return lhs == rhs
165-
case let (lhs as UInt64, rhs as UInt64):
166-
return lhs == rhs
167-
case let (lhs as Float, rhs as Float):
168-
return lhs == rhs
169-
case let (lhs as Double, rhs as Double):
170-
return lhs == rhs
171-
case let (lhs as String, rhs as String):
172-
return lhs == rhs
173-
case let (lhs as [String: AnyEncodable], rhs as [String: AnyEncodable]):
174-
return lhs == rhs
175-
case let (lhs as [AnyEncodable], rhs as [AnyEncodable]):
176-
return lhs == rhs
177-
default:
178-
return false
179-
}
180-
}
181-
}
182-
183140
extension AnyEncodable: CustomStringConvertible {
184141
public var description: String {
185142
switch value {
@@ -286,4 +243,8 @@ extension AnyEncodable: Hashable {
286243
break
287244
}
288245
}
246+
247+
public static func ==(lhs: AnyEncodable, rhs: AnyEncodable) -> Bool {
248+
return lhs.hashValue == rhs.hashValue
249+
}
289250
}

0 commit comments

Comments
 (0)