Skip to content

Commit c82e1de

Browse files
authored
Merge pull request #2134 from lorentey/delete-unnecessary-hashable-impls
2 parents 84b6511 + 5d000d0 commit c82e1de

13 files changed

+8
-140
lines changed

Foundation/FileManager.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -884,14 +884,6 @@ public struct FileAttributeKey : RawRepresentable, Equatable, Hashable {
884884
self.rawValue = rawValue
885885
}
886886

887-
public func hash(into hasher: inout Hasher) {
888-
hasher.combine(rawValue)
889-
}
890-
891-
public static func ==(_ lhs: FileAttributeKey, _ rhs: FileAttributeKey) -> Bool {
892-
return lhs.rawValue == rhs.rawValue
893-
}
894-
895887
public static let type = FileAttributeKey(rawValue: "NSFileType")
896888
public static let size = FileAttributeKey(rawValue: "NSFileSize")
897889
public static let modificationDate = FileAttributeKey(rawValue: "NSFileModificationDate")
@@ -928,14 +920,6 @@ public struct FileAttributeType : RawRepresentable, Equatable, Hashable {
928920
self.rawValue = rawValue
929921
}
930922

931-
public func hash(into hasher: inout Hasher) {
932-
hasher.combine(rawValue)
933-
}
934-
935-
public static func ==(_ lhs: FileAttributeType, _ rhs: FileAttributeType) -> Bool {
936-
return lhs.rawValue == rhs.rawValue
937-
}
938-
939923
#if os(Windows)
940924
internal init(attributes: WIN32_FILE_ATTRIBUTE_DATA, atPath path: String) {
941925
if attributes.dwFileAttributes & DWORD(FILE_ATTRIBUTE_DIRECTORY) == DWORD(FILE_ATTRIBUTE_DIRECTORY) {

Foundation/HTTPCookie.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ public struct HTTPCookiePropertyKey : RawRepresentable, Equatable, Hashable {
1717
public init(rawValue: String) {
1818
self.rawValue = rawValue
1919
}
20-
21-
public func hash(into hasher: inout Hasher) {
22-
hasher.combine(rawValue)
23-
}
24-
25-
public static func ==(_ lhs: HTTPCookiePropertyKey, _ rhs: HTTPCookiePropertyKey) -> Bool {
26-
return lhs.rawValue == rhs.rawValue
27-
}
2820
}
2921

3022
extension HTTPCookiePropertyKey {

Foundation/NSAttributedString.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ extension NSAttributedString {
2020
public init(rawValue: String) {
2121
self.rawValue = rawValue
2222
}
23-
24-
public func hash(into hasher: inout Hasher) {
25-
hasher.combine(rawValue)
26-
}
27-
28-
public static func ==(left: NSAttributedString.Key, right: NSAttributedString.Key) -> Bool {
29-
return left.rawValue == right.rawValue
30-
}
3123
}
3224
}
3325

Foundation/NSCalendar.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ extension NSCalendar {
6666
self.rawValue = rawValue
6767
}
6868

69-
public func hash(into hasher: inout Hasher) {
70-
hasher.combine(rawValue)
71-
}
72-
7369
public static let gregorian = NSCalendar.Identifier("gregorian")
7470
public static let buddhist = NSCalendar.Identifier("buddhist")
7571
public static let chinese = NSCalendar.Identifier("chinese")
@@ -137,10 +133,6 @@ extension NSCalendar {
137133
}
138134

139135
extension NSCalendar.Identifier {
140-
public static func ==(_ lhs: NSCalendar.Identifier, _ rhs: NSCalendar.Identifier) -> Bool {
141-
return lhs.rawValue == rhs.rawValue
142-
}
143-
144136
public static func <(_ lhs: NSCalendar.Identifier, _ rhs: NSCalendar.Identifier) -> Bool {
145137
return lhs.rawValue < rhs.rawValue
146138
}

Foundation/NSDecimalNumber.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ public struct NSExceptionName : RawRepresentable, Equatable, Hashable {
1818
public init(rawValue: String) {
1919
self.rawValue = rawValue
2020
}
21-
22-
public func hash(into hasher: inout Hasher) {
23-
hasher.combine(rawValue)
24-
}
25-
26-
public static func ==(_ lhs: NSExceptionName, _ rhs: NSExceptionName) -> Bool {
27-
return lhs.rawValue == rhs.rawValue
28-
}
2921
}
3022

3123
extension NSExceptionName {

Foundation/NSLocale.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,6 @@ extension NSLocale {
177177
self.rawValue = rawValue
178178
}
179179

180-
public func hash(into hasher: inout Hasher) {
181-
hasher.combine(rawValue)
182-
}
183-
184180
public static let identifier = NSLocale.Key(rawValue: "kCFLocaleIdentifierKey")
185181
public static let languageCode = NSLocale.Key(rawValue: "kCFLocaleLanguageCodeKey")
186182
public static let countryCode = NSLocale.Key(rawValue: "kCFLocaleCountryCodeKey")
@@ -213,13 +209,6 @@ extension NSLocale {
213209
}
214210

215211

216-
extension NSLocale.Key {
217-
public static func ==(_ lhs: NSLocale.Key, _ rhs: NSLocale.Key) -> Bool {
218-
return lhs.rawValue == rhs.rawValue
219-
}
220-
}
221-
222-
223212
extension NSLocale {
224213
public static let currentLocaleDidChangeNotification = NSNotification.Name(rawValue: "kCFLocaleCurrentLocaleDidChangeNotification")
225214
}

Foundation/NSNotification.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ open class NSNotification: NSObject, NSCopying, NSCoding {
1313
public init(rawValue: String) {
1414
self.rawValue = rawValue
1515
}
16-
17-
public func hash(into hasher: inout Hasher) {
18-
hasher.combine(rawValue)
19-
}
20-
21-
public static func ==(lhs: Name, rhs: Name) -> Bool {
22-
return lhs.rawValue == rhs.rawValue
23-
}
2416
}
2517

2618
private(set) open var name: Name

Foundation/NSString.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,6 @@ extension NSString {
115115

116116
public let rawValue: String
117117

118-
public var hashValue: Int {
119-
return self.rawValue.hashValue
120-
}
121-
122-
public static func ==(_ lhs: StringTransform, _ rhs: StringTransform) -> Bool {
123-
return lhs.rawValue == rhs.rawValue
124-
}
125-
126118
public init(_ rawValue: String) {
127119
self.rawValue = rawValue
128120
}

Foundation/NSURL.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,6 @@ public struct URLResourceKey : RawRepresentable, Equatable, Hashable {
7575
public init(_ rawValue: String) {
7676
self.rawValue = rawValue
7777
}
78-
79-
public func hash(into hasher: inout Hasher) {
80-
hasher.combine(rawValue)
81-
}
82-
83-
public static func ==(lhs: URLResourceKey, rhs: URLResourceKey) -> Bool {
84-
return lhs.rawValue == rhs.rawValue
85-
}
8678
}
8779

8880
extension URLResourceKey {
@@ -197,14 +189,6 @@ public struct URLFileResourceType : RawRepresentable, Equatable, Hashable {
197189
public init(_ rawValue: String) {
198190
self.rawValue = rawValue
199191
}
200-
201-
public func hash(into hasher: inout Hasher) {
202-
hasher.combine(rawValue)
203-
}
204-
205-
public static func ==(lhs: URLFileResourceType, rhs: URLFileResourceType) -> Bool {
206-
return lhs.rawValue == rhs.rawValue
207-
}
208192
}
209193

210194
extension URLFileResourceType {

Foundation/Progress.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,7 @@ open class Progress : NSObject {
399399
public let rawValue: String
400400
public init(_ rawValue: String) { self.rawValue = rawValue }
401401
public init(rawValue: String) { self.rawValue = rawValue }
402-
public func hash(into hasher: inout Hasher) { hasher.combine(rawValue) }
403-
public static func ==(_ lhs: FileOperationKind, _ rhs: FileOperationKind) -> Bool { return lhs.rawValue == rhs.rawValue }
404-
402+
405403
/// Use for indicating the progress represents a download.
406404
public static let downloading = FileOperationKind(rawValue: "NSProgressFileOperationKindDownloading")
407405

@@ -478,9 +476,7 @@ public struct ProgressKind : RawRepresentable, Equatable, Hashable {
478476
public let rawValue: String
479477
public init(_ rawValue: String) { self.rawValue = rawValue }
480478
public init(rawValue: String) { self.rawValue = rawValue }
481-
public func hash(into hasher: inout Hasher) { hasher.combine(rawValue) }
482-
public static func ==(_ lhs: ProgressKind, _ rhs: ProgressKind) -> Bool { return lhs.rawValue == rhs.rawValue }
483-
479+
484480
/// Indicates that the progress being performed is related to files.
485481
///
486482
/// Progress of this kind is assumed to use bytes as the unit of work being done and the default implementation of `localizedDescription` takes advantage of that to return more specific text than it could otherwise.
@@ -491,9 +487,7 @@ public struct ProgressUserInfoKey : RawRepresentable, Equatable, Hashable {
491487
public let rawValue: String
492488
public init(_ rawValue: String) { self.rawValue = rawValue }
493489
public init(rawValue: String) { self.rawValue = rawValue }
494-
public func hash(into hasher: inout Hasher) { hasher.combine(rawValue) }
495-
public static func ==(_ lhs: ProgressUserInfoKey, _ rhs: ProgressUserInfoKey) -> Bool { return lhs.rawValue == rhs.rawValue }
496-
490+
497491
/// How much time is probably left in the operation, as an NSNumber containing a number of seconds.
498492
///
499493
/// If this value is present, then `Progress` can present a more detailed `localizedAdditionalDescription`.

Foundation/Stream.swift

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ extension Stream {
2828
public init(rawValue: String) {
2929
self.rawValue = rawValue
3030
}
31-
32-
public func hash(into hasher: inout Hasher) {
33-
hasher.combine(rawValue)
34-
}
35-
36-
public static func ==(lhs: Stream.PropertyKey, rhs: Stream.PropertyKey) -> Bool {
37-
return lhs.rawValue == rhs.rawValue
38-
}
3931
}
4032

4133
public enum Status : UInt {
@@ -303,12 +295,6 @@ public struct StreamSocketSecurityLevel : RawRepresentable, Equatable, Hashable
303295
public init(rawValue: String) {
304296
self.rawValue = rawValue
305297
}
306-
public func hash(into hasher: inout Hasher) {
307-
hasher.combine(rawValue)
308-
}
309-
public static func ==(lhs: StreamSocketSecurityLevel, rhs: StreamSocketSecurityLevel) -> Bool {
310-
return lhs.rawValue == rhs.rawValue
311-
}
312298
}
313299
extension StreamSocketSecurityLevel {
314300
public static let none = StreamSocketSecurityLevel(rawValue: "kCFStreamSocketSecurityLevelNone")
@@ -325,12 +311,6 @@ public struct StreamSOCKSProxyConfiguration : RawRepresentable, Equatable, Hasha
325311
public init(rawValue: String) {
326312
self.rawValue = rawValue
327313
}
328-
public func hash(into hasher: inout Hasher) {
329-
hasher.combine(rawValue)
330-
}
331-
public static func ==(lhs: StreamSOCKSProxyConfiguration, rhs: StreamSOCKSProxyConfiguration) -> Bool {
332-
return lhs.rawValue == rhs.rawValue
333-
}
334314
}
335315
extension StreamSOCKSProxyConfiguration {
336316
public static let hostKey = StreamSOCKSProxyConfiguration(rawValue: "NSStreamSOCKSProxyKey")
@@ -347,12 +327,6 @@ public struct StreamSOCKSProxyVersion : RawRepresentable, Equatable, Hashable {
347327
public init(rawValue: String) {
348328
self.rawValue = rawValue
349329
}
350-
public func hash(into hasher: inout Hasher) {
351-
hasher.combine(rawValue)
352-
}
353-
public static func ==(lhs: StreamSOCKSProxyVersion, rhs: StreamSOCKSProxyVersion) -> Bool {
354-
return lhs.rawValue == rhs.rawValue
355-
}
356330
}
357331
extension StreamSOCKSProxyVersion {
358332
public static let version4 = StreamSOCKSProxyVersion(rawValue: "kCFStreamSocketSOCKSVersion4")
@@ -366,12 +340,6 @@ public struct StreamNetworkServiceTypeValue : RawRepresentable, Equatable, Hasha
366340
public init(rawValue: String) {
367341
self.rawValue = rawValue
368342
}
369-
public func hash(into hasher: inout Hasher) {
370-
hasher.combine(rawValue)
371-
}
372-
public static func ==(lhs: StreamNetworkServiceTypeValue, rhs: StreamNetworkServiceTypeValue) -> Bool {
373-
return lhs.rawValue == rhs.rawValue
374-
}
375343
}
376344
extension StreamNetworkServiceTypeValue {
377345
public static let voIP = StreamNetworkServiceTypeValue(rawValue: "kCFStreamNetworkServiceTypeVoIP")

Foundation/StringEncodings.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,7 @@ extension String {
6868
}
6969

7070
extension String.Encoding : Hashable {
71-
public func hash(into hasher: inout Hasher) {
72-
hasher.combine(rawValue)
73-
}
74-
75-
public static func ==(lhs: String.Encoding, rhs: String.Encoding) -> Bool {
76-
return lhs.rawValue == rhs.rawValue
77-
}
71+
// ==, hash(into:) supplied by RawRepresentable
7872
}
7973

8074
extension String.Encoding : CustomStringConvertible {

TestFoundation/TestNSCache.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,15 @@ class TestNSCache : XCTestCase {
117117

118118
class TestHashableCacheKey: Hashable {
119119
let string: String
120-
var hashValue: Int { return string.hashValue }
121120

122121
init(string: String) {
123122
self.string = string
124123
}
125124

125+
func hash(into hasher: inout Hasher) {
126+
hasher.combine(string)
127+
}
128+
126129
static func ==(lhs: TestHashableCacheKey,
127130
rhs:TestHashableCacheKey) -> Bool {
128131
return lhs.string == rhs.string

0 commit comments

Comments
 (0)