-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of ChatChannel and ChatMessage equality #3335
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,27 +237,28 @@ extension ChatChannel: AnyChannel {} | |
|
||
extension ChatChannel: Hashable { | ||
public static func == (lhs: ChatChannel, rhs: ChatChannel) -> Bool { | ||
lhs.cid == rhs.cid && | ||
lhs.updatedAt == rhs.updatedAt && | ||
lhs.cooldownDuration == rhs.cooldownDuration && | ||
lhs.createdAt == rhs.createdAt && | ||
lhs.createdBy == rhs.createdBy && | ||
lhs.deletedAt == rhs.deletedAt && | ||
lhs.extraData == rhs.extraData && | ||
lhs.imageURL == rhs.imageURL && | ||
lhs.isFrozen == rhs.isFrozen && | ||
lhs.isHidden == rhs.isHidden && | ||
lhs.lastMessageAt == rhs.lastMessageAt && | ||
lhs.memberCount == rhs.memberCount && | ||
lhs.membership == rhs.membership && | ||
lhs.muteDetails == rhs.muteDetails && | ||
lhs.name == rhs.name && | ||
lhs.ownCapabilities == rhs.ownCapabilities && | ||
lhs.previewMessage == rhs.previewMessage && | ||
lhs.reads == rhs.reads && | ||
lhs.team == rhs.team && | ||
lhs.truncatedAt == rhs.truncatedAt && | ||
lhs.watcherCount == rhs.watcherCount | ||
guard lhs.cid == rhs.cid else { return false } | ||
guard lhs.updatedAt == rhs.updatedAt else { return false } | ||
guard lhs.lastMessageAt == rhs.lastMessageAt else { return false } | ||
guard lhs.muteDetails == rhs.muteDetails else { return false } | ||
guard lhs.reads == rhs.reads else { return false } | ||
guard lhs.previewMessage == rhs.previewMessage else { return false } | ||
guard lhs.name == rhs.name else { return false } | ||
guard lhs.watcherCount == rhs.watcherCount else { return false } | ||
Comment on lines
+240
to
+247
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I fully understood the issue 🤔 Isn't this the same code?
What it is different from not using a guard? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like compiler produces slightly different code where now it does not copy channels and messages so much as it used to be with a long expression. |
||
guard lhs.createdAt == rhs.createdAt else { return false } | ||
guard lhs.cooldownDuration == rhs.cooldownDuration else { return false } | ||
guard lhs.createdBy == rhs.createdBy else { return false } | ||
guard lhs.deletedAt == rhs.deletedAt else { return false } | ||
guard lhs.extraData == rhs.extraData else { return false } | ||
guard lhs.imageURL == rhs.imageURL else { return false } | ||
guard lhs.isFrozen == rhs.isFrozen else { return false } | ||
guard lhs.isHidden == rhs.isHidden else { return false } | ||
guard lhs.memberCount == rhs.memberCount else { return false } | ||
guard lhs.membership == rhs.membership else { return false } | ||
guard lhs.team == rhs.team else { return false } | ||
guard lhs.truncatedAt == rhs.truncatedAt else { return false } | ||
guard lhs.ownCapabilities == rhs.ownCapabilities else { return false } | ||
return true | ||
} | ||
|
||
public func hash(into hasher: inout Hasher) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you also changed the order, did that have an impact?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly re-ordered them depending on my gut feeling what could change more often. Nothing really noticeable. I have seen ownCapabilities being the most visible.