Skip to content

Commit

Permalink
Use arity hashCode instead of proc#hash in CallableSelector (#4494)
Browse files Browse the repository at this point in the history
Using proc#hash as the cache key means that you're only
guaranteed to get a cache hit if exactly the same proc is
being passed. Using arity.hashCode instead should satisfy the
original reason for hashing the proc (disambiguate signatures
based on the arity of the proc) while preventing cache misses.

Also note that this was causing a memory leak: executing the
code that relies on this caching would create a new cache entry
on every invocation, slowly growing the size of the cache.
snowp authored and kares committed Feb 19, 2017
1 parent 339c72d commit b0b1d52
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
@@ -744,7 +744,7 @@ private static int javaClassHashCode(final IRubyObject arg) {
private static int javaClassOrProcHashCode(final IRubyObject arg) {
// if ( arg == null ) return 0;
final Class<?> javaClass = arg.getJavaClass();
return javaClass == RubyProc.class ? arg.hashCode() : javaClass.hashCode();
return javaClass == RubyProc.class ? ((RubyProc) arg).arity().hashCode() : javaClass.hashCode();
}

private static Class<?> getJavaClass(final IRubyObject arg) {

0 comments on commit b0b1d52

Please sign in to comment.