Skip to content

Commit 04f85be

Browse files
committed
[Truffle] No need for a FixnumOrBignumNode for ObjectIDOperations.
* They produce Bignums on purpose.
1 parent 535bc52 commit 04f85be

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

truffle/src/main/java/org/jruby/truffle/nodes/rubinius/ObjectPrimitiveNodes.java

+2-15
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ public abstract class ObjectPrimitiveNodes {
2929
@RubiniusPrimitive(name = "object_id")
3030
public abstract static class ObjectIDPrimitiveNode extends RubiniusPrimitiveNode {
3131

32-
@Child private FixnumOrBignumNode fixnumOrBignum;
33-
3432
public ObjectIDPrimitiveNode(RubyContext context, SourceSection sourceSection) {
3533
super(context, sourceSection);
3634
}
3735

3836
public ObjectIDPrimitiveNode(ObjectIDPrimitiveNode prev) {
3937
super(prev);
40-
fixnumOrBignum = prev.fixnumOrBignum;
4138
}
4239

4340
public abstract Object executeObjectID(VirtualFrame frame, Object value);
@@ -83,23 +80,13 @@ public Object objectID(long value) {
8380
if (isSmallFixnum(value)) {
8481
return ObjectIDOperations.smallFixnumToID(value);
8582
} else {
86-
if (fixnumOrBignum == null) {
87-
CompilerDirectives.transferToInterpreter();
88-
fixnumOrBignum = insert(new FixnumOrBignumNode(getContext(), getSourceSection()));
89-
}
90-
91-
return fixnumOrBignum.fixnumOrBignum(ObjectIDOperations.largeFixnumToID(value));
83+
return ObjectIDOperations.largeFixnumToID(getContext(), value);
9284
}
9385
}
9486

9587
@Specialization
9688
public Object objectID(double value) {
97-
if (fixnumOrBignum == null) {
98-
CompilerDirectives.transferToInterpreter();
99-
fixnumOrBignum = insert(new FixnumOrBignumNode(getContext(), getSourceSection()));
100-
}
101-
102-
return fixnumOrBignum.fixnumOrBignum(ObjectIDOperations.floatToID(value));
89+
return ObjectIDOperations.floatToID(getContext(), value);
10390
}
10491

10592
@Specialization

truffle/src/main/java/org/jruby/truffle/runtime/ObjectIDOperations.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ public static long smallFixnumToID(long fixnum) {
6363
return fixnum * 2 + 1;
6464
}
6565

66-
public static BigInteger largeFixnumToID(long fixnum) {
66+
public static RubyBignum largeFixnumToID(RubyContext context, long fixnum) {
6767
assert !isSmallFixnum(fixnum);
68-
return BigInteger.valueOf(fixnum).or(LARGE_FIXNUM_FLAG);
68+
return new RubyBignum(context.getCoreLibrary().getBignumClass(), BigInteger.valueOf(fixnum).or(LARGE_FIXNUM_FLAG));
6969
}
7070

71-
public static BigInteger floatToID(double value) {
71+
public static RubyBignum floatToID(RubyContext context, double value) {
7272
long bits = Double.doubleToRawLongBits(value);
73-
return BigInteger.valueOf(bits).or(FLOAT_FLAG);
73+
return new RubyBignum(context.getCoreLibrary().getBignumClass(), BigInteger.valueOf(bits).or(FLOAT_FLAG));
7474
}
7575

7676
// ID => primitive

0 commit comments

Comments
 (0)