From ffaa630f3467bebb0f0eda0f6f3fb99cc2010d95 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 7 Dec 2019 14:23:51 -0800 Subject: [PATCH] Improve performance of finding updated articles by improving performance of comparing articles by improving performance of comparing authors. --- Frameworks/Articles/Author.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Frameworks/Articles/Author.swift b/Frameworks/Articles/Author.swift index 7debc8868..3bedce5bd 100644 --- a/Frameworks/Articles/Author.swift +++ b/Frameworks/Articles/Author.swift @@ -53,6 +53,20 @@ public struct Author: Codable, Hashable { } return nil } + + // MARK: - Hashable + + public func hash(into hasher: inout Hasher) { + hasher.combine(authorID) + } + + // MARK: - Equatable + + static public func ==(lhs: Author, rhs: Author) -> Bool { + // The authorID is a calculation based on all the properties, + // and so it’s a quick shortcut to determine equality. + return lhs.authorID == rhs.authorID + } } extension Set where Element == Author {