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

Fixed MIDIObject's hash implementation #181

Merged
merged 4 commits into from
Jun 12, 2017
Merged

Fixed MIDIObject's hash implementation #181

merged 4 commits into from
Jun 12, 2017

Conversation

nightbirdsevolve
Copy link
Contributor

MIDIUniqueID 's type being SInt32, ie. an int, it is not directly compatible with -hash which is unsigned int. I've seen many unique IDs being negative and when they get cast to UInt, their value ends up being 18446744073709551160 ie. NSUIntegerMax which is not at all unique.
Hence, we start to return similar hashes for different MIDI objects.

This simple fix uses NSNumber's native hash implementation.

Copy link
Member

@armadsen armadsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the good PR! I do have one clarifying question below.

- (void)setUniqueID:(MIDIUniqueID)uniqueID
{
_uniqueID = uniqueID;
_hash = @(uniqueID).hash;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did profiling indicate that caching the hash value actually makes an important performance difference in a real application? If not, I'd probably prefer the simpler approach of just doing -(NSUInteger)hash { return [@(self.uniqueID) hash]; }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not do any profiling, just went for the best performance approach, just adds a bunch of lines, so… as you wish feel free to change that ;)

@armadsen armadsen merged commit 7387fcb into mixedinkey-opensource:master Jun 12, 2017
@armadsen
Copy link
Member

Thanks for this! Finally merging it now.

@nightbirdsevolve nightbirdsevolve deleted the Fix-MIDIObject-Hash branch June 12, 2017 16:14
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