Skip to content

Commit

Permalink
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -93,8 +93,6 @@
import java.util.Arrays;
import java.util.Comparator;

import static org.jruby.runtime.Helpers.hashEnd;
import static org.jruby.runtime.Helpers.murmurCombine;
import static org.jruby.truffle.core.array.ArrayHelpers.createArray;
import static org.jruby.truffle.core.array.ArrayHelpers.getSize;
import static org.jruby.truffle.core.array.ArrayHelpers.getStore;
@@ -920,13 +918,14 @@ protected Object fillFallback(VirtualFrame frame, DynamicObject array, Object[]
public abstract static class HashNode extends ArrayCoreMethodNode {

@Child private ToIntNode toIntNode;
@Child private CallDispatchHeadNode toHashNode;

@Specialization(guards = "isNullArray(array)")
public long hashNull(VirtualFrame frame, DynamicObject array) {
public long hashNull(DynamicObject array) {
final int arraySize = 0;
long h = Helpers.hashStart(getContext().getJRubyRuntime(), arraySize);
h = Helpers.murmurCombine(h, System.identityHashCode(ArrayNodes.class));
h = hashEnd(h);
h = Helpers.hashEnd(h);
return h;
}

@@ -936,6 +935,7 @@ public long hash(VirtualFrame frame, DynamicObject array,
@Cached("new()") SnippetNode snippetNode) {

final int arraySize = getSize(array);
// TODO BJF Jul 4, 2016 Seed could be chosen in advance to avoid branching
long h = Helpers.hashStart(getContext().getJRubyRuntime(), arraySize);
h = Helpers.murmurCombine(h, System.identityHashCode(ArrayNodes.class));
final ArrayMirror store = strategy.newMirror(array);
@@ -944,11 +944,11 @@ public long hash(VirtualFrame frame, DynamicObject array,

for (; n < arraySize; n++) {
final Object value = store.get(n);
final long valueHash = toLong(frame, snippetNode.execute(frame, "value.hash", "value", value));
h = murmurCombine(h, valueHash);
final long valueHash = toLong(frame, callToHash(frame, value));
h = Helpers.murmurCombine(h, valueHash);
}

h = hashEnd(h);
h = Helpers.hashEnd(h);
return h;
}

@@ -964,6 +964,14 @@ private long toLong(VirtualFrame frame, Object indexObject) {
return (long) result;
}
}

protected Object callToHash(VirtualFrame frame, Object object) {
if (toHashNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
toHashNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
}
return toHashNode.call(frame, object, "hash", null);
}
}

@CoreMethod(names = "include?", required = 1)

0 comments on commit 0b67b6c

Please sign in to comment.