@@ -4,22 +4,23 @@ import Foundation
44/// decoding `BSONValue`s of unknown type.
55public struct AnyBSONValue : Codable , Equatable , Hashable {
66 // TODO: conform all `BSONValue` types to `Hashable` (SWIFT-320).
7- // swiftlint:disable:next legacy_hashing
8- public var hashValue : Int {
7+ public func hash ( into hasher : inout Hasher ) {
8+ hasher . combine ( self . value . bsonType )
99 // A few types need to be handled specifically because their string representations aren't sufficient or
1010 // performant.
1111 if let date = self . value as? Date {
1212 // `Date`'s string conversion omits milliseconds and smaller time units, and using a string formatter is
1313 // expensive. Instead, we just include the time interval itself.
14- return " \( self . value . bsonType ) - \ ( date. timeIntervalSince1970) " . hashValue
14+ hasher . combine ( date. timeIntervalSince1970)
1515 } else if let binary = self . value as? Binary {
1616 // `Binary`'s string representation omits the data itself, so we include its hashValue.
17- return " \( self . value. bsonType) - \( binary. data. hashValue) - \( binary. subtype) " . hashValue
17+ hasher. combine ( binary. data)
18+ hasher. combine ( binary. subtype)
1819 } else if let arr = self . value as? [ BSONValue ] {
1920 // To factor in every item in the array, we include the arrays extended JSON representation.
20- return " \( self . value . bsonType ) - \ (( [ " value " : arr] as Document ) . extendedJSON) " . hashValue
21+ hasher . combine ( ( [ " value " : arr] as Document ) . extendedJSON)
2122 }
22- return " \( self . value. bsonType ) - \( self . value ) " . hashValue
23+ hasher . combine ( " \( self . value) " )
2324 }
2425
2526 /// The `BSONValue` wrapped by this struct.
0 commit comments