-
-
Save headius/570f7f97edf0b6596e981865aa57c70b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/src/main/java/org/jruby/RubyHash.java b/core/src/main/java/org/jruby/RubyHash.java | |
index f87c491604..39ccd4084b 100644 | |
--- a/core/src/main/java/org/jruby/RubyHash.java | |
+++ b/core/src/main/java/org/jruby/RubyHash.java | |
@@ -2162,8 +2162,7 @@ public class RubyHash extends RubyObject implements Map { | |
if (this == otherHash) return this; | |
- alloc(); | |
- copyFrom(this, otherHash, otherHash.isComparedByIdentity()); | |
+ replaceWith(context, otherHash); | |
ifNone = otherHash.ifNone; | |
@@ -2176,6 +2175,25 @@ public class RubyHash extends RubyObject implements Map { | |
return this; | |
} | |
+ protected void replaceWith(ThreadContext context, RubyHash otherHash) { | |
+ if (otherHash.getClass() == RubyHash.class) { | |
+ alloc(); | |
+ copyFrom(this, otherHash, otherHash.isComparedByIdentity()); | |
+ } else { | |
+ replaceExternally(context, otherHash); | |
+ } | |
+ } | |
+ | |
+ protected void replaceExternally(ThreadContext context, RubyHash otherHash) { | |
+ rb_clear(context); | |
+ | |
+ if (!isComparedByIdentity() && otherHash.isComparedByIdentity()) { | |
+ setComparedByIdentity(true); | |
+ } | |
+ | |
+ otherHash.visitAll(context, ReplaceVisitor, this); | |
+ } | |
+ | |
private static final VisitorWithState<RubyHash> ReplaceVisitor = new VisitorWithState<RubyHash>() { | |
@Override | |
public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, RubyHash target) { | |
diff --git a/core/src/main/java/org/jruby/java/proxies/MapJavaProxy.java b/core/src/main/java/org/jruby/java/proxies/MapJavaProxy.java | |
index 5503fc1a31..b3ba23ed94 100644 | |
--- a/core/src/main/java/org/jruby/java/proxies/MapJavaProxy.java | |
+++ b/core/src/main/java/org/jruby/java/proxies/MapJavaProxy.java | |
@@ -385,6 +385,11 @@ public final class MapJavaProxy extends ConcreteJavaProxy { | |
@Override | |
public final Set directEntrySet() { return entrySet(); } | |
+ @Override | |
+ protected void replaceWith(ThreadContext context, RubyHash otherHash) { | |
+ replaceExternally(context, otherHash); | |
+ } | |
+ | |
} | |
@JRubyMethod(name = "default") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment