Idea is to extract different Strategy classes (e.g. OpenAddressStrategy, LinearSearchStrategy) for hash algorithms which we forward to in RubyHash.
Initial approach can be found here: https://github.com/ChrisBr/jruby/commits/performance/hash-extract-class-2
- A lot of changes, high probability that something break
- The Strategy classes are still highly coupled to the RubyHash class as we need to hand over a lot of attributes / variables:
- flags to calculate the hash value (we could calc the hash in RubyHash and hand it over but then rehashing also needs to happen in RubyHash class?)
- The methods in the Strategy classes need to be very granular and composed in RubyHash (e.g. check for existence and adding of a RubyString as we need to freeze the string if it doesn't exist (see
op_asetForString
) or check for iterating (checkIterating
))
- Iterations over key/value pairs need to happen in the Strategy class to be fast, otherwise we need again a temp RubyHashEntry class to use in an iterator (see
visitAll
) - RubyHash needs to know about about
DELETED_BIN
orEMPTY_BIN
values to compose the methods - We still need RubyHash to not break API (e.g.
getEntry
,EntryView
)
- Strategy classes are relatively simple to implement