diff --git a/Postbox.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist b/Postbox.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist index ef8b19e937..6e406df74a 100644 --- a/Postbox.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/Postbox.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist @@ -12,7 +12,7 @@ PostboxMac.xcscheme orderHint - 5 + 4 PostboxTests.xcscheme diff --git a/Postbox/ChatListHole.swift b/Postbox/ChatListHole.swift index 2ac25803ad..c03ca3e1ca 100644 --- a/Postbox/ChatListHole.swift +++ b/Postbox/ChatListHole.swift @@ -14,12 +14,8 @@ public struct ChatListHole: Hashable, CustomStringConvertible { public var hashValue: Int { return self.index.hashValue } -} -public func ==(lhs: ChatListHole, rhs: ChatListHole) -> Bool { - return lhs.index == rhs.index -} - -public func <(lhs: ChatListHole, rhs: ChatListHole) -> Bool { - return lhs.index < rhs.index + public static func <(lhs: ChatListHole, rhs: ChatListHole) -> Bool { + return lhs.index < rhs.index + } } diff --git a/Postbox/Coding.swift b/Postbox/Coding.swift index 2f00d2379f..c9238a6334 100644 --- a/Postbox/Coding.swift +++ b/Postbox/Coding.swift @@ -107,10 +107,10 @@ public class MemoryBuffer: Equatable, CustomStringConvertible { public func withDataNoCopy(_ f: (Data) -> Void) { f(Data(bytesNoCopy: self.memory, count: self.length, deallocator: .none)) } -} - -public func ==(lhs: MemoryBuffer, rhs: MemoryBuffer) -> Bool { - return lhs.length == rhs.length && memcmp(lhs.memory, rhs.memory, lhs.length) == 0 + + public static func ==(lhs: MemoryBuffer, rhs: MemoryBuffer) -> Bool { + return lhs.length == rhs.length && memcmp(lhs.memory, rhs.memory, lhs.length) == 0 + } } public final class WriteBuffer: MemoryBuffer { diff --git a/Postbox/GroupFeedReadState.swift b/Postbox/GroupFeedReadState.swift index 34fca449fb..9ec18e8611 100644 --- a/Postbox/GroupFeedReadState.swift +++ b/Postbox/GroupFeedReadState.swift @@ -7,13 +7,6 @@ public struct GroupFeedReadState: Equatable { self.maxReadIndex = maxReadIndex } - public static func ==(lhs: GroupFeedReadState, rhs: GroupFeedReadState) -> Bool { - if lhs.maxReadIndex != rhs.maxReadIndex { - return false - } - return true - } - func isIncomingMessageIndexRead(_ index: MessageIndex) -> Bool { return self.maxReadIndex >= index } diff --git a/Postbox/Media.swift b/Postbox/Media.swift index 65d58ce65e..37abdeb503 100644 --- a/Postbox/Media.swift +++ b/Postbox/Media.swift @@ -74,10 +74,6 @@ public struct MediaId: Hashable, PostboxCoding, CustomStringConvertible { } } -public func ==(lhs: MediaId, rhs: MediaId) -> Bool { - return lhs.id == rhs.id && lhs.namespace == rhs.namespace -} - public protocol AssociatedMediaData: class, PostboxCoding { func isEqual(to: AssociatedMediaData) -> Bool } diff --git a/Postbox/Message.swift b/Postbox/Message.swift index 367d60b731..3d53a5b03e 100644 --- a/Postbox/Message.swift +++ b/Postbox/Message.swift @@ -74,24 +74,19 @@ public struct MessageId: Hashable, Comparable, CustomStringConvertible { } return array } -} -public func ==(lhs: MessageId, rhs: MessageId) -> Bool { - return lhs.id == rhs.id && lhs.namespace == rhs.namespace && lhs.peerId == rhs.peerId -} - -public func <(lhs: MessageId, rhs: MessageId) -> Bool { - if lhs.namespace == rhs.namespace { - if lhs.id == rhs.id { - return lhs.peerId < rhs.peerId + public static func <(lhs: MessageId, rhs: MessageId) -> Bool { + if lhs.namespace == rhs.namespace { + if lhs.id == rhs.id { + return lhs.peerId < rhs.peerId + } else { + return lhs.id < rhs.id + } } else { - return lhs.id < rhs.id + return lhs.namespace < rhs.namespace } - } else { - return lhs.namespace < rhs.namespace } } - public struct MessageIndex: Comparable, Hashable { public let id: MessageId public let timestamp: Int32 @@ -159,22 +154,18 @@ public struct MessageIndex: Comparable, Hashable { func withPeerId(_ peerId: PeerId) -> MessageIndex { return MessageIndex(id: MessageId(peerId: peerId, namespace: self.id.namespace, id: self.id.id), timestamp: self.timestamp) } -} -public func ==(lhs: MessageIndex, rhs: MessageIndex) -> Bool { - return lhs.id == rhs.id && lhs.timestamp == rhs.timestamp -} - -public func <(lhs: MessageIndex, rhs: MessageIndex) -> Bool { - if lhs.timestamp != rhs.timestamp { - return lhs.timestamp < rhs.timestamp + public static func <(lhs: MessageIndex, rhs: MessageIndex) -> Bool { + if lhs.timestamp != rhs.timestamp { + return lhs.timestamp < rhs.timestamp + } + + if lhs.id.namespace != rhs.id.namespace { + return lhs.id.namespace < rhs.id.namespace + } + + return lhs.id.id < rhs.id.id } - - if lhs.id.namespace != rhs.id.namespace { - return lhs.id.namespace < rhs.id.namespace - } - - return lhs.id.id < rhs.id.id } public struct ChatListIndex: Comparable, Hashable { @@ -186,10 +177,6 @@ public struct ChatListIndex: Comparable, Hashable { self.messageIndex = messageIndex } - public static func ==(lhs: ChatListIndex, rhs: ChatListIndex) -> Bool { - return lhs.pinningIndex == rhs.pinningIndex && lhs.messageIndex == rhs.messageIndex - } - public static func <(lhs: ChatListIndex, rhs: ChatListIndex) -> Bool { if let lhsPinningIndex = lhs.pinningIndex, let rhsPinningIndex = rhs.pinningIndex { if lhsPinningIndex > rhsPinningIndex { @@ -415,30 +402,30 @@ public struct MessageForwardInfo: Equatable { public let sourceMessageId: MessageId? public let date: Int32 public let authorSignature: String? -} -public func ==(lhs: MessageForwardInfo, rhs: MessageForwardInfo) -> Bool { - if !lhs.author.isEqual(rhs.author) { - return false - } - if let lhsSource = lhs.source, let rhsSource = rhs.source { - if !lhsSource.isEqual(rhsSource) { + public static func ==(lhs: MessageForwardInfo, rhs: MessageForwardInfo) -> Bool { + if !lhs.author.isEqual(rhs.author) { return false } - } else if (lhs.source == nil) != (rhs.source == nil) { - return false + if let lhsSource = lhs.source, let rhsSource = rhs.source { + if !lhsSource.isEqual(rhsSource) { + return false + } + } else if (lhs.source == nil) != (rhs.source == nil) { + return false + } + if lhs.sourceMessageId != rhs.sourceMessageId { + return false + } + if lhs.date != rhs.date { + return false + } + if lhs.authorSignature != rhs.authorSignature { + return false + } + + return true } - if lhs.sourceMessageId != rhs.sourceMessageId { - return false - } - if lhs.date != rhs.date { - return false - } - if lhs.authorSignature != rhs.authorSignature { - return false - } - - return true } public protocol MessageAttribute: PostboxCoding { @@ -458,10 +445,6 @@ public extension MessageAttribute { public struct MessageGroupInfo: Equatable { public let stableId: UInt32 - - public static func ==(lhs: MessageGroupInfo, rhs: MessageGroupInfo) -> Bool { - return lhs.stableId == rhs.stableId - } } public final class Message { diff --git a/Postbox/MessageHistoryHole.swift b/Postbox/MessageHistoryHole.swift index 8d00276ca6..bf588064b8 100644 --- a/Postbox/MessageHistoryHole.swift +++ b/Postbox/MessageHistoryHole.swift @@ -20,8 +20,4 @@ public struct MessageHistoryHole: Equatable, CustomStringConvertible { public var description: String { return "MessageHistoryHole(peerId: \(self.maxIndex.id.peerId), min: \(self.min), max: \(self.maxIndex.id.id))" } - - public static func ==(lhs: MessageHistoryHole, rhs: MessageHistoryHole) -> Bool { - return lhs.maxIndex == rhs.maxIndex && lhs.min == rhs.min && lhs.tags == rhs.tags - } } diff --git a/Postbox/Peer.swift b/Postbox/Peer.swift index 6dba130f30..8cd1c6044c 100644 --- a/Postbox/Peer.swift +++ b/Postbox/Peer.swift @@ -59,7 +59,6 @@ public struct PeerId: Hashable, CustomStringConvertible, Comparable { } public init(_ buffer: ReadBuffer) { - var namespace: Int32 = 0 var id: Int32 = 0 memcpy(&namespace, buffer.memory, 4) @@ -74,22 +73,18 @@ public struct PeerId: Hashable, CustomStringConvertible, Comparable { buffer.write(&namespace, offset: 0, length: 4); buffer.write(&id, offset: 0, length: 4); } -} -public func ==(lhs: PeerId, rhs: PeerId) -> Bool { - return lhs.id == rhs.id && lhs.namespace == rhs.namespace -} - -public func <(lhs: PeerId, rhs: PeerId) -> Bool { - if lhs.namespace != rhs.namespace { - return lhs.namespace < rhs.namespace + public static func <(lhs: PeerId, rhs: PeerId) -> Bool { + if lhs.namespace != rhs.namespace { + return lhs.namespace < rhs.namespace + } + + if lhs.id != rhs.id { + return lhs.id < rhs.id + } + + return false } - - if lhs.id != rhs.id { - return lhs.id < rhs.id - } - - return false } public protocol Peer: class, PostboxCoding { diff --git a/Postbox/PeerNameIndexRepresentation.swift b/Postbox/PeerNameIndexRepresentation.swift index 1974c29db3..e94beda690 100644 --- a/Postbox/PeerNameIndexRepresentation.swift +++ b/Postbox/PeerNameIndexRepresentation.swift @@ -4,23 +4,6 @@ public enum PeerIndexNameRepresentation: Equatable { case title(title: String, addressName: String?) case personName(first: String, last: String, addressName: String?, phoneNumber: String?) - public static func ==(lhs: PeerIndexNameRepresentation, rhs: PeerIndexNameRepresentation) -> Bool { - switch lhs { - case let .title(lhsTitle, lhsAddressName): - if case let .title(rhsTitle, rhsAddressName) = rhs, lhsTitle == rhsTitle, lhsAddressName == rhsAddressName { - return true - } else { - return false - } - case let .personName(lhsFirst, lhsLast, lhsAddressName, lhsPhoneNumber): - if case let .personName(rhsFirst, rhsLast, rhsAddressName, rhsPhoneNumber) = rhs, lhsFirst == rhsFirst, lhsLast == rhsLast, lhsAddressName == rhsAddressName, lhsPhoneNumber == rhsPhoneNumber { - return true - } else { - return false - } - } - } - public var isEmpty: Bool { switch self { case let .title(title, addressName): diff --git a/Postbox/PeerReadState.swift b/Postbox/PeerReadState.swift index 0f7f5bf258..e803e99566 100644 --- a/Postbox/PeerReadState.swift +++ b/Postbox/PeerReadState.swift @@ -30,23 +30,6 @@ public enum PeerReadState: Equatable, CustomStringConvertible { } } - public static func ==(lhs: PeerReadState, rhs: PeerReadState) -> Bool { - switch lhs { - case let .idBased(maxIncomingReadId, maxOutgoingReadId, maxKnownId, count): - if case .idBased(maxIncomingReadId, maxOutgoingReadId, maxKnownId, count) = rhs { - return true - } else { - return false - } - case let .indexBased(maxIncomingReadIndex, maxOutgoingReadIndex, count): - if case .indexBased(maxIncomingReadIndex, maxOutgoingReadIndex, count) = rhs { - return true - } else { - return false - } - } - } - func isIncomingMessageIndexRead(_ index: MessageIndex) -> Bool { switch self { case let .idBased(maxIncomingReadId, _, _, _):