Skip to content

Commit 79ee920

Browse files
committed
Use size for Integer ranges unless it comes back nil
Without this we would hang on (1..2**100).count, added to test_range.rb:test_count after 3.1.
1 parent ef5543c commit 79ee920

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

core/src/main/java/org/jruby/RubyRange.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,13 @@ public IRubyObject call(ThreadContext ctx, IRubyObject larg, Block blk) {
11671167
public IRubyObject count(ThreadContext context, Block block) {
11681168
if (isBeginless || isEndless) return RubyFloat.newFloat(context.runtime, RubyFloat.INFINITY);
11691169

1170+
if (begin instanceof RubyInteger) {
1171+
IRubyObject size = size(context);
1172+
if (!size.isNil()) {
1173+
return size;
1174+
}
1175+
}
1176+
11701177
return RubyEnumerable.count(context, this, block);
11711178
}
11721179

0 commit comments

Comments
 (0)