ReactKit / SwiftState

Elegant state machine for Swift.
MIT License
904 stars 93 forks source link

Do not use hashValue in comparison #44

Closed siyusong closed 8 years ago

siyusong commented 8 years ago

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 commented 8 years ago

Hi @siyusong, Thanks for pull request! This is really a nice catch :+1: