GitHub user paplorinc opened a pull request:
https://github.com/apache/groovy/pull/360
Changed the `Range`'s step to `Number` instead of `int`
A revival of https://github.com/apache/groovy/pull/120
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/paplorinc/incubator-groovy RangeNumberStepSize
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/groovy/pull/360.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #360
----
commit 69c40f79dd8b34da177c99291009acc54c964aa9
Author: Pap LÅrinc <[email protected]>
Date: 2016-06-29T17:28:42Z
Changed the Range's step to `Number` instead of `int`
Until now a `Range` could only step by an integer value, even if its
elements had other types, e.g. doubles.
This made stepping over ranges like `0.1..0.9`strange, as that resulted in
a single element.
Also, stepping over `ObjectRange` instances (like the above one) called the
`next`/`previous` method reflectively,
even if the range had a numeric type (the most common case).
This made it ~10x slower than e.g. `IntRange`.
The new implementation changed the `step` type to `Number` and unified the
way stepping is done in
`ObjectRange` and `IntRange`, making them as fast as the original
`IntRange` for numeric cases.
Also, `IntRange` treats the overflow issue by storing the intermediary
value in a `Long` directly.
At the boundaries, the `next` and `previous` methods may now wrap to the
other extreme - or return null.
----
---
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.
---