array.c: eql? identity check if immediate value #1206
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I previously opened this: #1200
This PR introduces similar performance improvements for 'immediate' (Fixnum, floats, etc..) values, whilst not changing behaviour for
Float::NAN
or objects with redefinedeql?
methods.caveat: This does change behaviour if you monkey patch the
eql?
method for an immedate value class, but if you're doing that, I imagine Array#eql? is going to be low down on your list of problems.Benchmarks
Marked improvement for arrays of immediate values: https://gist.github.com/dwfait/da225dcc4687dcaff2a5
No apparent degradation of performance for arrays of objects / non-immediate values: https://gist.github.com/dwfait/9add4b6442897d68a2cd
Float::NAN
As mentioned, in this PR treatment of Float::NAN is as before:
However, I did not create a test for this, because Matz has stated comparison of NaN to NaN is undefined: https://bugs.ruby-lang.org/issues/1720
I have however included a test which I believe addresses the core of that issue - of objects where
eql?
will return false, even to itself.