Skip to content
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

Do not use hashValue in comparison #44

Merged
merged 1 commit into from
Feb 24, 2016
Merged

Do not use hashValue in comparison #44

merged 1 commit into from
Feb 24, 2016

Conversation

siyusong
Copy link
Contributor

Hi @inamiy,

First of all, thank you for creating this amazing library!

When exploring the codebase, I found that hashValues are used in comparison in a few places. This seems a logic error: x == y implies x.hashValue == y.hashValue, but not the other way around. Therefore, using hashValue in comparison, technically speaking, is not reliable because of potential hash collision.

I understand that in many cases, we are comparing two hash value generated by SwiftState classes, and hash collision is unlikely/impossible. However, the concrete Event/State types will be implemented by the client (user of SwiftState), so there is no way to guarantee that hash collision won't happen.

I have removed all occurrences of comparison of hashValues, and reimplemented them using plain old pattern matching. Please let me know your thoughts on this.

@inamiy
Copy link
Member

inamiy commented Feb 24, 2016

Hi @siyusong,
Thanks for pull request! This is really a nice catch 👍

inamiy added a commit that referenced this pull request Feb 24, 2016
@inamiy inamiy merged commit a0bfd80 into ReactKit:swift/2.0 Feb 24, 2016
@inamiy inamiy added this to the 4.1.0 milestone Feb 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants