Skip to content

Commit 6f9bf85

Browse files
committed
Handle non-long cases for hash start.
1 parent bf46d96 commit 6f9bf85

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/main/java/org/truffleruby/core/VMPrimitiveNodes.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,30 @@ public abstract static class VMHashStart extends PrimitiveArrayArgumentsNode {
452452
public long startHash(long salt) {
453453
return getContext().getHashing(this).start(salt);
454454
}
455+
456+
@Specialization(guards = "isRubyBignum(salt)")
457+
public long startHashBigNum(DynamicObject salt) {
458+
return getContext().getHashing(this).start(Layouts.BIGNUM.getValue(salt).hashCode());
459+
}
460+
461+
@Specialization(guards = "!isRubyNumber(salt)")
462+
public Object startHashNotNumber(Object salt,
463+
@Cached("createPrivate()") CallDispatchHeadNode coerceToIntNode,
464+
@Cached("createBinaryProfile()") ConditionProfile isIntegerProfile,
465+
@Cached("createBinaryProfile()") ConditionProfile isLongProfile,
466+
@Cached("createBinaryProfile()") ConditionProfile isBignumProfile) {
467+
Object result = coerceToIntNode.call(coreLibrary().getTruffleTypeModule(), "coerce_to_int", salt);
468+
if (isIntegerProfile.profile(result instanceof Integer)) {
469+
return getContext().getHashing(this).start((int) result);
470+
} else if (isLongProfile.profile(result instanceof Long)) {
471+
return getContext().getHashing(this).start((long) result);
472+
} else if (isBignumProfile.profile(Layouts.BIGNUM.isBignum(result))) {
473+
return getContext().getHashing(this).start(Layouts.BIGNUM.getValue((DynamicObject) result).hashCode());
474+
} else {
475+
throw new UnsupportedOperationException();
476+
}
477+
478+
}
455479
}
456480

457481
@Primitive(name = "vm_hash_update", needsSelf = false)

0 commit comments

Comments
 (0)