You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by paplorinc <gi...@git.apache.org> on 2016/07/05 10:11:28 UTC
[GitHub] groovy pull request #360: `ObjectRange` and `IntRange` iteration and steppin...
Github user paplorinc commented on a diff in the pull request:
https://github.com/apache/groovy/pull/360#discussion_r69538290
--- Diff: src/main/groovy/lang/IntRange.java ---
@@ -385,26 +385,23 @@ public void step(int step, Closure closure) {
return; // from == to and step == 0, nothing to do, so return
}
- if (isReverse()) {
- step = -step;
+ final long from = getFrom().longValue(), to = getTo().longValue();
+
+ final boolean isAscending;
+ if (step < 0) {
+ step *= -1;
+ isAscending = isReverse();
+ } else {
+ isAscending = !isReverse();
}
- if (step > 0) {
- int value = getFrom();
- while (value <= getTo()) {
+
+ if (isAscending) {
--- End diff --
its easier to think about ascending and descending iterations than with bigger from values with negative step sizes...
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---