From 94265ecab916ef8d505ce843c8d8cf00d3f792d3 Mon Sep 17 00:00:00 2001 From: Ian Leitch Date: Tue, 31 Oct 2023 12:23:49 +0100 Subject: [PATCH] Stop conflating Hashable and Equatable. Closes #647 --- Sources/PeripheryKit/Indexer/Declaration.swift | 8 ++++---- Sources/PeripheryKit/Indexer/Reference.swift | 8 ++++---- Sources/PeripheryKit/Indexer/SourceLocation.swift | 9 +++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Sources/PeripheryKit/Indexer/Declaration.swift b/Sources/PeripheryKit/Indexer/Declaration.swift index 03b4f2d92..b015cfbcb 100644 --- a/Sources/PeripheryKit/Indexer/Declaration.swift +++ b/Sources/PeripheryKit/Indexer/Declaration.swift @@ -198,7 +198,7 @@ final class Declaration { var isImplicit: Bool = false var isObjcAccessible: Bool = false - private let identifier: Int + private let hashValueCache: Int var ancestralDeclarations: Set { var maybeParent = parent @@ -251,7 +251,7 @@ final class Declaration { self.kind = kind self.usrs = usrs self.location = location - self.identifier = usrs.hashValue + self.hashValueCache = usrs.hashValue } func isDeclaredInExtension(kind: Declaration.Kind) -> Bool { @@ -262,13 +262,13 @@ final class Declaration { extension Declaration: Hashable { func hash(into hasher: inout Hasher) { - hasher.combine(identifier) + hasher.combine(hashValueCache) } } extension Declaration: Equatable { static func == (lhs: Declaration, rhs: Declaration) -> Bool { - lhs.identifier == rhs.identifier + lhs.usrs == rhs.usrs } } diff --git a/Sources/PeripheryKit/Indexer/Reference.swift b/Sources/PeripheryKit/Indexer/Reference.swift index 2551047cf..942f5e8d8 100644 --- a/Sources/PeripheryKit/Indexer/Reference.swift +++ b/Sources/PeripheryKit/Indexer/Reference.swift @@ -30,14 +30,14 @@ final class Reference { let usr: String var role: Role = .unknown - private let identifier: Int + private let hashValueCache: Int init(kind: Declaration.Kind, usr: String, location: SourceLocation, isRelated: Bool = false) { self.kind = kind self.usr = usr self.isRelated = isRelated self.location = location - self.identifier = [usr.hashValue, location.hashValue, isRelated.hashValue].hashValue + self.hashValueCache = [usr.hashValue, location.hashValue, isRelated.hashValue].hashValue } var descendentReferences: Set { @@ -47,13 +47,13 @@ final class Reference { extension Reference: Hashable { func hash(into hasher: inout Hasher) { - hasher.combine(identifier) + hasher.combine(hashValueCache) } } extension Reference: Equatable { static func == (lhs: Reference, rhs: Reference) -> Bool { - lhs.identifier == rhs.identifier + lhs.usr == rhs.usr && lhs.location == rhs.location && lhs.isRelated == rhs.isRelated } } diff --git a/Sources/PeripheryKit/Indexer/SourceLocation.swift b/Sources/PeripheryKit/Indexer/SourceLocation.swift index 32b9c4d41..6af1a8eae 100644 --- a/Sources/PeripheryKit/Indexer/SourceLocation.swift +++ b/Sources/PeripheryKit/Indexer/SourceLocation.swift @@ -5,13 +5,13 @@ class SourceLocation { let line: Int let column: Int - private let identifier: Int + private let hashValueCache: Int init(file: SourceFile, line: Int, column: Int) { self.file = file self.line = line self.column = column - self.identifier = [file.hashValue, line, column].hashValue + self.hashValueCache = [file.hashValue, line, column].hashValue } // MARK: - Private @@ -31,13 +31,14 @@ class SourceLocation { extension SourceLocation: Equatable { static func == (lhs: SourceLocation, rhs: SourceLocation) -> Bool { - lhs.identifier == rhs.identifier + lhs.file == rhs.file && lhs.line == rhs.line && lhs.column == rhs.column } } extension SourceLocation: Hashable { func hash(into hasher: inout Hasher) { - hasher.combine(identifier) + + hasher.combine(hashValueCache) } }