Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Call site caching for Array#==.
Browse files Browse the repository at this point in the history
headius committed Jul 21, 2016
1 parent 2f8b532 commit b303a4c
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -2852,10 +2852,10 @@ public IRubyObject op_cmp(ThreadContext context, IRubyObject obj) {
IRubyObject ary2 = runtime.getNil();
boolean isAnArray = (obj instanceof RubyArray) || obj.getMetaClass().getSuperClass() == runtime.getArray();

if (!isAnArray && !obj.respondsTo("to_ary")) {
if (!isAnArray && !sites(context).respond_to_to_ary.respondsTo(context, obj, obj, true)) {
return ary2;
} else if (!isAnArray) {
ary2 = obj.callMethod(context, "to_ary");
ary2 = sites(context).to_ary.call(context, obj, obj);
} else {
ary2 = obj.convertToArray();
}
@@ -2872,8 +2872,10 @@ private IRubyObject cmpCommon(ThreadContext context, Ruby runtime, RubyArray ary
int len = realLength;
if (len > ary2.realLength) len = ary2.realLength;

CallSite cmp = sites(context).cmp;
for (int i = 0; i < len; i++) {
IRubyObject v = invokedynamic(context, elt(i), OP_CMP, ary2.elt(i));
IRubyObject elt = elt(i);
IRubyObject v = cmp.call(context, elt, elt, ary2.elt(i));
if (!(v instanceof RubyFixnum) || ((RubyFixnum) v).getLongValue() != 0) return v;
}
} finally {
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/runtime/JavaSites.java
Original file line number Diff line number Diff line change
@@ -71,6 +71,9 @@ public static class KernelSites {
}
public static class ArraySites {
public final CheckedSites to_ary_checked = new CheckedSites("to_ary");
public final RespondToCallSite respond_to_to_ary = new RespondToCallSite("to_ary");
public final CallSite to_ary = new FunctionalCachingCallSite("to_ary");
public final CallSite cmp = new FunctionalCachingCallSite("<=>");
}

public static class StringSites {

0 comments on commit b303a4c

Please sign in to comment.