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

Empty hash optimization #1676

Merged
merged 2 commits into from Jul 27, 2014
Merged

Commits on May 1, 2014

  1. Optimize key-based Hash access for empty hashes

    This avoids performing the potentially expensive hash computation in
    the event that the Hash is empty, as there cannot possibly be a match.
    grddev committed May 1, 2014
    Copy the full SHA
    ad4521e View commit details
    Browse the repository at this point in the history
  2. Conform to MRI behaviour for empty hashes

    In the event that the `#hash` method has side effects, any optimisation
    with respect to empty hashes will affect the results of the operations.
    
    For MRI, the empty-hash optimisation seems to be applied everywhere in
    2.0.0 and beyond. In 1.9.3 the #hash method is not called for #[] and
    #key?, but strangely enough the performance is not improved for empty
    hashes. In 1.8.7, the #hash method is always called even if empty.
    
    This does not match the semantics of MRI exactly, as this avoids calling
    the #hash method from #values_at in 1.9.3, but that would be slightly
    more involved to implement.
    grddev committed May 1, 2014
    Copy the full SHA
    68d4185 View commit details
    Browse the repository at this point in the history