Permalink
Browse files

[Truffle] Do not call #hash on compare_by_identity Hash in Hash#[].

  • Loading branch information...
eregon committed Apr 1, 2016
1 parent feb3c57 commit 5b4cdca0177f03a3ba110571aa26e60ec39ebdfe
Showing with 31 additions and 13 deletions.
  1. +31 −13 truffle/src/main/java/org/jruby/truffle/core/hash/HashNodes.java
@@ -253,9 +253,8 @@ protected boolean equal(VirtualFrame frame, Object key1, Object key2) {
}
@ExplodeLoop
@Specialization(guards = "isPackedHash(hash)", contains = "getConstantIndexPackedArray")
@Specialization(guards = { "isPackedHash(hash)", "!isCompareByIdentity(hash)" }, contains = "getConstantIndexPackedArray")
public Object getPackedArray(VirtualFrame frame, DynamicObject hash, Object key,
@Cached("createBinaryProfile()") ConditionProfile byIdentityProfile,
@Cached("create()") BranchProfile notInHashProfile,
@Cached("create()") BranchProfile useDefaultProfile) {
final int hashed = hashNode.hash(frame, key);
@@ -265,24 +264,43 @@ public Object getPackedArray(VirtualFrame frame, DynamicObject hash, Object key,
for (int n = 0; n < getContext().getOptions().HASH_PACKED_ARRAY_MAX; n++) {
if (n < size) {
if (hashed == PackedArrayStrategy.getHashed(store, n)) {
final boolean equal;
if (hashed == PackedArrayStrategy.getHashed(store, n) &&
eql(frame, key, PackedArrayStrategy.getKey(store, n))) {
return PackedArrayStrategy.getValue(store, n);
}
}
}
if (byIdentityProfile.profile(Layouts.HASH.getCompareByIdentity(hash))) {
equal = equal(frame, key, PackedArrayStrategy.getKey(store, n));
} else {
equal = eql(frame, key, PackedArrayStrategy.getKey(store, n));
}
notInHashProfile.enter();
if (equal) {
return PackedArrayStrategy.getValue(store, n);
}
if (undefinedValue != null) {
return undefinedValue;
}
useDefaultProfile.enter();
return callDefaultNode.call(frame, hash, "default", null, key);
}
@ExplodeLoop
@Specialization(guards = { "isPackedHash(hash)", "isCompareByIdentity(hash)" },
contains = "getConstantIndexPackedArray")
public Object getPackedArrayByIdentity(VirtualFrame frame, DynamicObject hash, Object key,
@Cached("create()") BranchProfile notInHashProfile,
@Cached("create()") BranchProfile useDefaultProfile) {
final Object[] store = (Object[]) Layouts.HASH.getStore(hash);
final int size = Layouts.HASH.getSize(hash);
for (int n = 0; n < getContext().getOptions().HASH_PACKED_ARRAY_MAX; n++) {
if (n < size) {
if (equal(frame, key, PackedArrayStrategy.getKey(store, n))) {
return PackedArrayStrategy.getValue(store, n);
}
}
}
notInHashProfile.enter();
if (undefinedValue != null) {
return undefinedValue;
}

0 comments on commit 5b4cdca

Please sign in to comment.