Refactor Equatable implementations on ReferenceType and PointerType

This commit is contained in:
Matt Rubin 2019-04-12 15:38:20 -04:00
parent 778596b71a
commit 743083d19d
2 changed files with 10 additions and 9 deletions

View File

@ -17,11 +17,12 @@ public protocol PointerType: Hashable {
var type: git_otype { get }
}
public func == <P: PointerType>(lhs: P, rhs: P) -> Bool {
return lhs.oid == rhs.oid && lhs.type.rawValue == rhs.type.rawValue
}
public extension PointerType {
static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.oid == rhs.oid
&& lhs.type == rhs.type
}
func hash(into hasher: inout Hasher) {
hasher.combine(oid)
}

View File

@ -20,12 +20,12 @@ public protocol ReferenceType {
var oid: OID { get }
}
public func ==<T: ReferenceType>(lhs: T, rhs: T) -> Bool {
return lhs.longName == rhs.longName
&& lhs.oid == rhs.oid
}
public extension ReferenceType {
static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.longName == rhs.longName
&& lhs.oid == rhs.oid
}
func hash(into hasher: inout Hasher) {
hasher.combine(longName)
hasher.combine(oid)