Skip to content

Commit 4b34eb5

Browse files
authored
Merge pull request #1820 from ikesyo/use-hash-into
2 parents 988e631 + 9ee6b02 commit 4b34eb5

11 files changed

+35
-33
lines changed

Foundation/Calendar.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,12 +859,12 @@ public struct Calendar : Hashable, Equatable, ReferenceConvertible, _MutableBoxi
859859

860860
// MARK: -
861861

862-
public var hashValue: Int {
862+
public func hash(into hasher: inout Hasher) {
863863
// We implement hash ourselves, because we need to make sure autoupdating calendars have the same hash
864864
if _autoupdating {
865-
return 1
865+
hasher.combine(1 as Int8)
866866
} else {
867-
return _handle.map { $0.hash }
867+
hasher.combine(_handle.map { $0 })
868868
}
869869
}
870870

Foundation/CharacterSet.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ public struct CharacterSet : ReferenceConvertible, Equatable, Hashable, SetAlgeb
169169
}
170170
}
171171

172-
public var hashValue: Int {
173-
return _mapUnmanaged { $0.hashValue }
172+
public func hash(into hasher: inout Hasher) {
173+
hasher.combine(_mapUnmanaged { $0 })
174174
}
175175

176176
public var description: String {

Foundation/DateComponents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ public struct DateComponents : ReferenceConvertible, Hashable, Equatable, _Mutab
302302

303303
// MARK: -
304304

305-
public var hashValue: Int {
306-
return _handle.map { $0.hash }
305+
public func hash(into hasher: inout Hasher) {
306+
hasher.combine(_handle.map { $0 })
307307
}
308308

309309
public static func ==(lhs: DateComponents, rhs: DateComponents) -> Bool {

Foundation/IndexSet.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
173173
_handle = _MutablePairHandle(NSIndexSet(), copying: false)
174174
}
175175

176-
public var hashValue: Int {
177-
return _handle.map { $0.hash }
176+
public func hash(into hasher: inout Hasher) {
177+
hasher.combine(_handle.map { $0 })
178178
}
179-
179+
180180
/// Returns the number of integers in `self`.
181181
public var count: Int {
182182
return _handle.map { $0.count }

Foundation/Locale.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,11 @@ public struct Locale : CustomStringConvertible, CustomDebugStringConvertible, Ha
421421
return _wrapped.debugDescription
422422
}
423423

424-
public var hashValue : Int {
424+
public func hash(into hasher: inout Hasher) {
425425
if _autoupdating {
426-
return 1
426+
hasher.combine(1 as Int8)
427427
} else {
428-
return _wrapped.hash
428+
hasher.combine(_wrapped)
429429
}
430430
}
431431

Foundation/Notification.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public struct Notification : ReferenceConvertible, Equatable, Hashable {
3636
self.object = object
3737
self.userInfo = userInfo
3838
}
39-
40-
public var hashValue: Int {
41-
return name.rawValue.hash
42-
}
4339

40+
public func hash(into hasher: inout Hasher) {
41+
hasher.combine(name)
42+
}
43+
4444
public var description: String {
4545
var description = "name = \(name.rawValue)"
4646
if let obj = object { description += ", object = \(obj)" }

Foundation/PersonNameComponents.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ public struct PersonNameComponents : ReferenceConvertible, Hashable, Equatable,
6868
set { _applyMutation { $0.phoneticRepresentation = newValue } }
6969
}
7070

71-
public var hashValue : Int {
72-
return _handle.map { $0.hash }
71+
public func hash(into hasher: inout Hasher) {
72+
hasher.combine(_handle.map { $0 })
7373
}
74-
74+
7575
public static func ==(lhs : PersonNameComponents, rhs: PersonNameComponents) -> Bool {
7676
// Don't copy references here; no one should be storing anything
7777
return lhs._handle._uncopiedReference().isEqual(rhs._handle._uncopiedReference())

Foundation/TimeZone.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ public struct TimeZone : Hashable, Equatable, ReferenceConvertible {
210210

211211
// MARK: -
212212

213-
public var hashValue : Int {
213+
public func hash(into hasher: inout Hasher) {
214214
if _autoupdating {
215-
return 1
215+
hasher.combine(1 as Int8)
216216
} else {
217-
return _wrapped.hash
217+
hasher.combine(_wrapped)
218218
}
219219
}
220220

Foundation/URL.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@ public struct URL : ReferenceConvertible, Equatable {
503503
_url = URL._converted(from: NSURL(fileURLWithFileSystemRepresentation: path, isDirectory: isDirectory, relativeTo: baseURL))
504504
}
505505

506-
public var hashValue: Int {
507-
return _url.hash
506+
public func hash(into hasher: inout Hasher) {
507+
hasher.combine(_url)
508508
}
509509

510510
// MARK: -

Foundation/URLComponents.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ public struct URLComponents : ReferenceConvertible, Hashable, Equatable, _Mutabl
274274
set { _applyMutation { $0.queryItems = newValue } }
275275
}
276276

277-
public var hashValue: Int {
278-
return _handle.map { $0.hash }
277+
public func hash(into hasher: inout Hasher) {
278+
hasher.combine(_handle.map { $0 })
279279
}
280-
280+
281281
// MARK: - Bridging
282282

283283
fileprivate init(reference: NSURLComponents) {
@@ -346,9 +346,11 @@ public struct URLQueryItem : ReferenceConvertible, Hashable, Equatable {
346346
get { return _queryItem.value }
347347
set { _queryItem = NSURLQueryItem(name: name, value: newValue) }
348348
}
349-
350-
public var hashValue: Int { return _queryItem.hash }
351-
349+
350+
public func hash(into hasher: inout Hasher) {
351+
hasher.combine(_queryItem)
352+
}
353+
352354
public static func ==(lhs: URLQueryItem, rhs: URLQueryItem) -> Bool {
353355
return lhs._queryItem.isEqual(rhs._queryItem)
354356
}

Foundation/URLRequest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ public struct URLRequest : ReferenceConvertible, Equatable, Hashable {
227227
}
228228
}
229229

230-
public var hashValue: Int {
231-
return _handle.map { $0.hashValue }
230+
public func hash(into hasher: inout Hasher) {
231+
hasher.combine(_handle.map { $0 })
232232
}
233233

234234
public static func ==(lhs: URLRequest, rhs: URLRequest) -> Bool {

0 commit comments

Comments
 (0)