Skip to content

Commit cd49b3e

Browse files
valeriomazzeombroadst
authored andcommitted
Fixed warnings introduced in Swift 5.0 (#242)
* Fixed warnings * Update to new hash function * Update AnyBSONValue.swift * Update BSONDecoder.swift
1 parent 8d5eb8b commit cd49b3e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Sources/MongoSwift/BSON/AnyBSONValue.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@ import Foundation
44
/// decoding `BSONValue`s of unknown type.
55
public 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.

Sources/MongoSwift/BSON/BSONDecoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ internal struct _BSONKey: CodingKey {
842842
internal static let `super` = _BSONKey(stringValue: "super")!
843843
}
844844

845-
internal extension DecodingError {
845+
extension DecodingError {
846846
internal static func _typeMismatch(at path: [CodingKey],
847847
expectation: Any.Type,
848848
reality: BSONValue) -> DecodingError {

0 commit comments

Comments
 (0)