From cf24dc9ed6c097e9334b092ceb755bababcac7b7 Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Thu, 11 Apr 2019 20:58:09 -0400 Subject: [PATCH] Migrate to the new method for Hashable conformance --- SwiftGit2/OID.swift | 16 +++------------- SwiftGit2/Objects.swift | 28 ++++++++++++++++------------ SwiftGit2/Pointers.swift | 8 ++++---- SwiftGit2/References.swift | 15 +++++++++------ SwiftGit2/Remotes.swift | 5 +++-- 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/SwiftGit2/OID.swift b/SwiftGit2/OID.swift index 2afdc61..45c6417 100644 --- a/SwiftGit2/OID.swift +++ b/SwiftGit2/OID.swift @@ -57,19 +57,9 @@ extension OID: CustomStringConvertible { } extension OID: Hashable { - public var hashValue: Int { - let bytes = [ - self.oid.id.0, - self.oid.id.1, - self.oid.id.2, - self.oid.id.3, - self.oid.id.4, - self.oid.id.5, - self.oid.id.6, - self.oid.id.7, - ] - return bytes.reduce(0) { (hash, byte) in - return Int(hash << 8) | Int(byte) + public func hash(into hasher: inout Hasher) { + withUnsafeBytes(of: oid.id) { + hasher.combine(bytes: $0) } } } diff --git a/SwiftGit2/Objects.swift b/SwiftGit2/Objects.swift index 3c815c0..eb95889 100644 --- a/SwiftGit2/Objects.swift +++ b/SwiftGit2/Objects.swift @@ -70,8 +70,10 @@ public struct Signature { } extension Signature: Hashable { - public var hashValue: Int { - return name.hashValue ^ email.hashValue ^ time.timeIntervalSince1970.hashValue + public func hash(into hasher: inout Hasher) { + hasher.combine(name) + hasher.combine(email) + hasher.combine(time) } } @@ -119,8 +121,8 @@ public struct Commit: ObjectType { } extension Commit: Hashable { - public var hashValue: Int { - return self.oid.hashValue + public func hash(into hasher: inout Hasher) { + hasher.combine(oid) } } @@ -175,8 +177,10 @@ public struct Tree: ObjectType { } extension Tree.Entry: Hashable { - public var hashValue: Int { - return Int(attributes) ^ object.hashValue ^ name.hashValue + public func hash(into hasher: inout Hasher) { + hasher.combine(attributes) + hasher.combine(object) + hasher.combine(name) } } @@ -193,8 +197,8 @@ public func == (lhs: Tree.Entry, rhs: Tree.Entry) -> Bool { } extension Tree: Hashable { - public var hashValue: Int { - return oid.hashValue + public func hash(into hasher: inout Hasher) { + hasher.combine(oid) } } @@ -218,8 +222,8 @@ public struct Blob: ObjectType { } extension Blob: Hashable { - public var hashValue: Int { - return oid.hashValue + public func hash(into hasher: inout Hasher) { + hasher.combine(oid) } } @@ -254,7 +258,7 @@ public struct Tag: ObjectType { } extension Tag: Hashable { - public var hashValue: Int { - return oid.hashValue + public func hash(into hasher: inout Hasher) { + hasher.combine(oid) } } diff --git a/SwiftGit2/Pointers.swift b/SwiftGit2/Pointers.swift index 49a7ce8..8fe7fe7 100644 --- a/SwiftGit2/Pointers.swift +++ b/SwiftGit2/Pointers.swift @@ -72,8 +72,8 @@ public enum Pointer: PointerType { } extension Pointer: Hashable { - public var hashValue: Int { - return oid.hashValue + public func hash(into hasher: inout Hasher) { + hasher.combine(oid) } } @@ -105,7 +105,7 @@ public struct PointerTo: PointerType { } extension PointerTo: Hashable { - public var hashValue: Int { - return oid.hashValue + public func hash(into hasher: inout Hasher) { + hasher.combine(oid) } } diff --git a/SwiftGit2/References.swift b/SwiftGit2/References.swift index fa8389d..7bbf3b2 100644 --- a/SwiftGit2/References.swift +++ b/SwiftGit2/References.swift @@ -57,8 +57,9 @@ public struct Reference: ReferenceType { } extension Reference: Hashable { - public var hashValue: Int { - return longName.hashValue ^ oid.hashValue + public func hash(into hasher: inout Hasher) { + hasher.combine(longName) + hasher.combine(oid) } } @@ -122,8 +123,9 @@ public struct Branch: ReferenceType { } extension Branch: Hashable { - public var hashValue: Int { - return longName.hashValue ^ oid.hashValue + public func hash(into hasher: inout Hasher) { + hasher.combine(longName) + hasher.combine(oid) } } @@ -194,7 +196,8 @@ public enum TagReference: ReferenceType { } extension TagReference: Hashable { - public var hashValue: Int { - return longName.hashValue ^ oid.hashValue + public func hash(into hasher: inout Hasher) { + hasher.combine(longName) + hasher.combine(oid) } } diff --git a/SwiftGit2/Remotes.swift b/SwiftGit2/Remotes.swift index 060a0ef..bcf7037 100644 --- a/SwiftGit2/Remotes.swift +++ b/SwiftGit2/Remotes.swift @@ -26,8 +26,9 @@ public struct Remote { } extension Remote: Hashable { - public var hashValue: Int { - return name.hashValue ^ URL.hashValue + public func hash(into hasher: inout Hasher) { + hasher.combine(name) + hasher.combine(URL) } }