Github user paplorinc commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/360#discussion_r69002046
  
    --- Diff: src/main/groovy/lang/IntRange.java ---
    @@ -355,40 +360,54 @@ public boolean containsAll(Collection other) {
             return super.containsAll(other);
         }
     
    +    @Override
         public void step(int step, Closure closure) {
    -        if (step == 0) {
    -            if (!getFrom().equals(getTo())) {
    +        step((Number) step, closure);
    +    }
    +
    +    /**
    +     * {@inheritDoc}
    +     */
    +    @Override
    +    public void step(Number step, Closure closure) {
    +        Long from = getFrom().longValue();
    +        Long to = getTo().longValue();
    +
    +        if (compareEqual(step, 0)) {
    +            if (compareNotEqual(from, to)) {
                     throw new GroovyRuntimeException("Infinite loop detected 
due to step size of 0");
                 } else {
                     return; // from == to and step == 0, nothing to do, so 
return
                 }
             }
     
    -        if (isReverse()) {
    -            step = -step;
    +        boolean isAscending = !isReverse();
    +        if (compareLessThan(step, 0)) {
    +            step = multiply(step, -1);
    +            isAscending = !isAscending;
             }
    -        if (step > 0) {
    -            int value = getFrom();
    -            while (value <= getTo()) {
    -                closure.call(Integer.valueOf(value));
    -                if ((0L + value + step) >= Integer.MAX_VALUE) {
    -                    break;
    -                }
    -                value = value + step;
    +
    +        if (isAscending) {
    +            for (Long value = from; value <= to; value = (Long) 
plus(value, step)) {
    --- End diff --
    
    iterating over a long, instead of constantly checking for overflow


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to