Skip to content

Commit c7a7788

Browse files
committed
Move range assert for RubyBignum in the RubyBignum constructor
1 parent ef4216f commit c7a7788

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/main/java/org/truffleruby/core/numeric/BignumOperations.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,9 @@
1313

1414
public class BignumOperations {
1515

16-
private static final BigInteger LONG_MIN_BIGINT = BigInteger.valueOf(Long.MIN_VALUE);
17-
private static final BigInteger LONG_MAX_BIGINT = BigInteger.valueOf(Long.MAX_VALUE);
18-
1916
public static RubyBignum createBignum(BigInteger value) {
20-
assert value.compareTo(LONG_MIN_BIGINT) < 0 ||
21-
value.compareTo(LONG_MAX_BIGINT) > 0 : "Bignum in long range : " + value;
22-
final RubyBignum instance = new RubyBignum(value);
2317
// TODO BJF Jul-30-2020 Add allocation tracing
24-
return instance;
18+
return new RubyBignum(value);
2519
}
2620

2721
}

src/main/java/org/truffleruby/core/numeric/RubyBignum.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323
@ExportLibrary(InteropLibrary.class)
2424
public final class RubyBignum extends ImmutableRubyObjectNotCopyable {
2525

26+
private static final BigInteger LONG_MIN_BIGINT = BigInteger.valueOf(Long.MIN_VALUE);
27+
private static final BigInteger LONG_MAX_BIGINT = BigInteger.valueOf(Long.MAX_VALUE);
28+
2629
public final BigInteger value;
2730

2831
public RubyBignum(BigInteger value) {
32+
assert value.compareTo(LONG_MIN_BIGINT) < 0 ||
33+
value.compareTo(LONG_MAX_BIGINT) > 0 : "Bignum in long range : " + value;
2934
this.value = value;
3035
}
3136

0 commit comments

Comments
 (0)