Skip to content

Commit

Permalink
Implement Range#to_a for RubyLongRange
Browse files Browse the repository at this point in the history
  • Loading branch information
Lillian Zhang committed Nov 27, 2020
1 parent 3483fb7 commit 83a9e9f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/java/org/truffleruby/core/range/RangeNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,30 @@ protected RubyArray toA(RubyIntRange range) {
}
}

@Specialization
protected RubyArray longtoA(RubyLongRange range) {
final long begin = range.begin;
long result;
if (range.excludedEnd) {
result = range.end;
} else {
result = range.end + 1;
}
final int length = (int) (result - begin);

if (length < 0) {
return createEmptyArray();
} else {
final long[] values = new long[length];

for (int n = 0; n < length; n++) {
values[n] = begin + n;
}

return createArray(values);
}
}

@Specialization(guards = "range.isBounded()")
protected Object boundedToA(RubyObjectRange range) {
if (toAInternalCall == null) {
Expand Down

0 comments on commit 83a9e9f

Please sign in to comment.