From cfb3bd706e5a5e606f36d3b80299e032a37bd43d Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 25 Aug 2018 11:54:58 -0700 Subject: [PATCH] Use new hash-into function instead of calculating hashValue. WIP on #402. --- Frameworks/Account/Account.swift | 8 ++++++-- Frameworks/Account/Feed.swift | 8 ++++++-- Frameworks/Account/Folder.swift | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index b5f198220..56bcfe44c 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -47,7 +47,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, public let accountID: String public let type: AccountType public var nameForDisplay = "" - public let hashValue: Int public var children = [AnyObject]() var urlToFeedDictionary = [String: Feed]() var idToFeedDictionary = [String: Feed]() @@ -106,7 +105,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, self.type = type self.settingsFile = settingsFile self.dataFolder = dataFolder - self.hashValue = accountID.hashValue let databaseFilePath = (dataFolder as NSString).appendingPathComponent("DB.sqlite3") self.database = ArticlesDatabase(databaseFilePath: databaseFilePath, accountID: accountID) @@ -479,6 +477,12 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } } + // MARK: - Hashable + + public func hash(into hasher: inout Hasher) { + hasher.combine(accountID) + } + // MARK: - Equatable public class func ==(lhs: Account, rhs: Account) -> Bool { diff --git a/Frameworks/Account/Feed.swift b/Frameworks/Account/Feed.swift index aa0cabb8b..c6d8c5454 100644 --- a/Frameworks/Account/Feed.swift +++ b/Frameworks/Account/Feed.swift @@ -30,7 +30,6 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable { public var conditionalGetInfo: HTTPConditionalGetInfo? public var contentHash: String? - public let hashValue: Int // MARK: - DisplayNameProvider @@ -61,7 +60,6 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable { self.accountID = accountID self.url = url self.feedID = feedID - self.hashValue = feedID.hashValue } // MARK: - Disk Dictionary @@ -162,6 +160,12 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable { contentHash = nil } + // MARK: - Hashable + + public func hash(into hasher: inout Hasher) { + hasher.combine(feedID) + } + // MARK: - Equatable public class func ==(lhs: Feed, rhs: Feed) -> Bool { diff --git a/Frameworks/Account/Folder.swift b/Frameworks/Account/Folder.swift index 74bd696ed..ad61f04c6 100644 --- a/Frameworks/Account/Folder.swift +++ b/Frameworks/Account/Folder.swift @@ -24,7 +24,6 @@ public final class Folder: DisplayNameProvider, Container, UnreadCountProvider, static let untitledName = NSLocalizedString("Untitled ƒ", comment: "Folder name") public let folderID: Int // not saved: per-run only static var incrementingID = 0 - public let hashValue: Int // MARK: - DisplayNameProvider @@ -52,7 +51,6 @@ public final class Folder: DisplayNameProvider, Container, UnreadCountProvider, let folderID = Folder.incrementingID Folder.incrementingID += 1 self.folderID = folderID - self.hashValue = folderID NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(childrenDidChange(_:)), name: .ChildrenDidChange, object: self) @@ -142,6 +140,12 @@ public final class Folder: DisplayNameProvider, Container, UnreadCountProvider, updateUnreadCount() } + // MARK: - Hashable + + public func hash(into hasher: inout Hasher) { + hasher.combine(folderID) + } + // MARK: - Equatable static public func ==(lhs: Folder, rhs: Folder) -> Bool {