Skip to content

Instantly share code, notes, and snippets.

@enebo
Created March 4, 2011 17:51
Show Gist options
  • Save enebo/855377 to your computer and use it in GitHub Desktop.
Save enebo/855377 to your computer and use it in GitHub Desktop.
diff --git a/src/org/jruby/RubyArray.java b/src/org/jruby/RubyArray.java
index 66f7982..4ec0bb2 100644
--- a/src/org/jruby/RubyArray.java
+++ b/src/org/jruby/RubyArray.java
@@ -67,6 +67,7 @@ import org.jruby.runtime.ThreadContext;
import static org.jruby.runtime.Visibility.*;
import static org.jruby.CompatVersion.*;
import org.jruby.runtime.builtin.IRubyObject;
+import org.jruby.runtime.callsite.CacheEntry;
import org.jruby.runtime.marshal.MarshalStream;
import org.jruby.runtime.marshal.UnmarshalStream;
import org.jruby.util.ByteList;
@@ -2420,12 +2421,13 @@ public class RubyArray extends RubyObject implements List {
public IRubyObject delete(ThreadContext context, IRubyObject item, Block block) {
int i2 = 0;
+ final CacheEntry[] cache = new CacheEntry[1];
Ruby runtime = context.getRuntime();
for (int i1 = 0; i1 < realLength; i1++) {
// Do not coarsen the "safe" check, since it will misinterpret AIOOBE from equalInternal
// See JRUBY-5434
IRubyObject e = safeArrayRef(values, begin + i1);
- if (equalInternal(context, e, item)) continue;
+ if (equalInternal(context, e, item, cache)) continue;
if (i1 != i2) store(i2, e);
i2++;
}
diff --git a/src/org/jruby/RubyObject.java b/src/org/jruby/RubyObject.java
index ced16b9..290791d 100644
--- a/src/org/jruby/RubyObject.java
+++ b/src/org/jruby/RubyObject.java
@@ -57,6 +57,7 @@ import org.jruby.runtime.ThreadContext;
import static org.jruby.runtime.Visibility.*;
import static org.jruby.CompatVersion.*;
import org.jruby.runtime.builtin.IRubyObject;
+import org.jruby.runtime.callsite.CacheEntry;
import org.jruby.runtime.marshal.DataType;
/**
@@ -356,6 +357,25 @@ public class RubyObject extends RubyBasicObject {
}
}
+ protected static boolean equalInternal(final ThreadContext context, final IRubyObject a, final IRubyObject b, final CacheEntry[] cache){
+ if (a == b) {
+ return true;
+ } else if (a instanceof RubySymbol) {
+ return false;
+ } else if (a instanceof RubyFixnum && b instanceof RubyFixnum) {
+ return ((RubyFixnum)a).fastEqual((RubyFixnum)b);
+ } else if (a instanceof RubyFloat && b instanceof RubyFloat) {
+ return ((RubyFloat)a).fastEqual((RubyFloat)b);
+ } else {
+ RubyClass metaclass = metaclass(a);
+ if (cache[0] == null || cache[0].token != a.getMetaClass().getCacheToken()) {
+ cache[0] = metaclass.searchWithCache("==");
+ }
+
+ return cache[0].method.call(context, a, metaclass, "==", b).isTrue();
+ }
+ }
+
/**
* Helper method for checking equality, first using Java identity
* equality, and then calling the "eql?" method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment