Skip to content

Do not use hashValue in comparison#44

Merged
inamiy merged 1 commit into
ReactKit:swift/2.0from
siyusong:fix-comparison-hashvalue
Feb 24, 2016
Merged

Do not use hashValue in comparison#44
inamiy merged 1 commit into
ReactKit:swift/2.0from
siyusong:fix-comparison-hashvalue

Conversation

@siyusong
Copy link
Copy Markdown
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
Copy Markdown
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