Provide hash(into:) functions where the default implementation might be doing too much work.
This commit is contained in:
parent
401050465e
commit
e275367664
@ -14,6 +14,7 @@ public protocol ContainerIdentifiable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum ContainerIdentifier: Hashable, Equatable, Sendable {
|
public enum ContainerIdentifier: Hashable, Equatable, Sendable {
|
||||||
|
|
||||||
case smartFeedController
|
case smartFeedController
|
||||||
case account(String) // accountID
|
case account(String) // accountID
|
||||||
case folder(String, String) // accountID, folderName
|
case folder(String, String) // accountID, folderName
|
||||||
@ -55,6 +56,20 @@ public enum ContainerIdentifier: Hashable, Equatable, Sendable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Hashable
|
||||||
|
|
||||||
|
public func hash(into hasher: inout Hasher) {
|
||||||
|
|
||||||
|
switch self {
|
||||||
|
case .smartFeedController:
|
||||||
|
hasher.combine(0)
|
||||||
|
case .account(let accountID):
|
||||||
|
hasher.combine(accountID)
|
||||||
|
case .folder(let accountID, let folderName):
|
||||||
|
hasher.combine(accountID)
|
||||||
|
hasher.combine(folderName)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ContainerIdentifier: Encodable {
|
extension ContainerIdentifier: Encodable {
|
||||||
|
@ -17,7 +17,7 @@ public struct KeyboardConstant {
|
|||||||
public static let spaceKey = " ".keyboardIntegerValue
|
public static let spaceKey = " ".keyboardIntegerValue
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension String {
|
extension String {
|
||||||
|
|
||||||
var keyboardIntegerValue: Int? {
|
var keyboardIntegerValue: Int? {
|
||||||
if isEmpty {
|
if isEmpty {
|
||||||
@ -65,6 +65,12 @@ public extension String {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Hashable
|
||||||
|
|
||||||
|
nonisolated public func hash(into hasher: inout Hasher) {
|
||||||
|
hasher.combine(key)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct KeyboardKey: Hashable, Sendable {
|
public struct KeyboardKey: Hashable, Sendable {
|
||||||
@ -143,5 +149,12 @@ public struct KeyboardKey: Hashable, Sendable {
|
|||||||
|
|
||||||
self.init(integerValue: integerValue, shiftKeyDown: shiftKeyDown, optionKeyDown: optionKeyDown, commandKeyDown: commandKeyDown, controlKeyDown: controlKeyDown)
|
self.init(integerValue: integerValue, shiftKeyDown: shiftKeyDown, optionKeyDown: optionKeyDown, commandKeyDown: commandKeyDown, controlKeyDown: controlKeyDown)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Hashable
|
||||||
|
|
||||||
|
public func hash(into hasher: inout Hasher) {
|
||||||
|
hasher.combine(integerValue)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -64,6 +64,12 @@ public struct FeedSpecifier: Hashable, Sendable {
|
|||||||
|
|
||||||
return currentBestFeed
|
return currentBestFeed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Hashable
|
||||||
|
|
||||||
|
public func hash(into hasher: inout Hasher) {
|
||||||
|
hasher.combine(urlString)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension FeedSpecifier {
|
private extension FeedSpecifier {
|
||||||
|
@ -144,6 +144,12 @@ typealias PasteboardFeedDictionary = [String: String]
|
|||||||
}
|
}
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Hashable
|
||||||
|
|
||||||
|
nonisolated func hash(into hasher: inout Hasher) {
|
||||||
|
hasher.combine(url)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Feed: PasteboardWriterOwner {
|
extension Feed: PasteboardWriterOwner {
|
||||||
|
@ -82,6 +82,12 @@ typealias PasteboardFolderDictionary = [String: String]
|
|||||||
}
|
}
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Hashable
|
||||||
|
|
||||||
|
nonisolated func hash(into hasher: inout Hasher) {
|
||||||
|
hasher.combine(name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Folder: PasteboardWriterOwner {
|
extension Folder: PasteboardWriterOwner {
|
||||||
|
@ -18,6 +18,11 @@ private struct TextFieldSizerSpecifier: Hashable {
|
|||||||
|
|
||||||
let numberOfLines: Int
|
let numberOfLines: Int
|
||||||
let font: NSFont
|
let font: NSFont
|
||||||
|
|
||||||
|
func hash(into hasher: inout Hasher) {
|
||||||
|
hasher.combine(numberOfLines)
|
||||||
|
hasher.combine(font.pointSize)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TextFieldSizeInfo {
|
struct TextFieldSizeInfo {
|
||||||
|
@ -18,6 +18,10 @@ public struct NewsBlurFeed: Hashable, Codable, Sendable {
|
|||||||
public let feedURL: String
|
public let feedURL: String
|
||||||
public let homePageURL: String?
|
public let homePageURL: String?
|
||||||
public let faviconURL: String?
|
public let faviconURL: String?
|
||||||
|
|
||||||
|
public func hash(into hasher: inout Hasher) {
|
||||||
|
hasher.combine(feedID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct NewsBlurFeedsResponse: Decodable, Sendable {
|
public struct NewsBlurFeedsResponse: Decodable, Sendable {
|
||||||
@ -29,6 +33,10 @@ public struct NewsBlurFeedsResponse: Decodable, Sendable {
|
|||||||
|
|
||||||
public let name: String
|
public let name: String
|
||||||
public let feedIDs: [Int]
|
public let feedIDs: [Int]
|
||||||
|
|
||||||
|
public func hash(into hasher: inout Hasher) {
|
||||||
|
hasher.combine(name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,10 @@ public struct NewsBlurStoryHashesResponse: Decodable, Sendable {
|
|||||||
self.hash = hash
|
self.hash = hash
|
||||||
self.timestamp = timestamp
|
self.timestamp = timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func hash(into hasher: inout Hasher) {
|
||||||
|
hasher.combine(hash)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,16 +25,16 @@ public struct ParsedAuthor: Hashable, Codable, Sendable {
|
|||||||
// MARK: - Hashable
|
// MARK: - Hashable
|
||||||
|
|
||||||
public func hash(into hasher: inout Hasher) {
|
public func hash(into hasher: inout Hasher) {
|
||||||
if let name = name {
|
if let name {
|
||||||
hasher.combine(name)
|
hasher.combine(name)
|
||||||
}
|
}
|
||||||
else if let url = url {
|
else if let url {
|
||||||
hasher.combine(url)
|
hasher.combine(url)
|
||||||
}
|
}
|
||||||
else if let emailAddress = emailAddress {
|
else if let emailAddress {
|
||||||
hasher.combine(emailAddress)
|
hasher.combine(emailAddress)
|
||||||
}
|
}
|
||||||
else if let avatarURL = avatarURL {
|
else if let avatarURL{
|
||||||
hasher.combine(avatarURL)
|
hasher.combine(avatarURL)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -44,4 +44,9 @@ public struct SyncStatus: Hashable, Equatable, Sendable {
|
|||||||
public func databaseDictionary() -> DatabaseDictionary {
|
public func databaseDictionary() -> DatabaseDictionary {
|
||||||
return [DatabaseKey.articleID: articleID, DatabaseKey.key: key.rawValue, DatabaseKey.flag: flag, DatabaseKey.selected: selected]
|
return [DatabaseKey.articleID: articleID, DatabaseKey.key: key.rawValue, DatabaseKey.flag: flag, DatabaseKey.selected: selected]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func hash(into hasher: inout Hasher) {
|
||||||
|
hasher.combine(articleID)
|
||||||
|
hasher.combine(key)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,11 @@ private struct UILabelSizerSpecifier: Hashable {
|
|||||||
|
|
||||||
let numberOfLines: Int
|
let numberOfLines: Int
|
||||||
let font: UIFont
|
let font: UIFont
|
||||||
|
|
||||||
|
func hash(into hasher: inout Hasher) {
|
||||||
|
hasher.combine(numberOfLines)
|
||||||
|
hasher.combine(font.pointSize)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TextFieldSizeInfo {
|
struct TextFieldSizeInfo {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user