Changed the Range's step to Number instead of int#120
Changed the Range's step to Number instead of int#120l0rinc wants to merge 1 commit intoapache:masterfrom
Conversation
|
Should play well with #109 |
|
your change currently has two obvious problems. (1) returning Collections.emptyList() is only ok, if you say, that the result cannot be modified. The old implementation did not have this. You even had to change a test for this. (2) You changed step(int) to step(Number). This is not binary compatible. Java programs using Range directly will have to recompile. They will do so just fine, since Java will do the boxing, but an old library will not work with these new Ranges |
|
Hello @blackdrag,
|
905ccfc to
4380948
Compare
|
An empty list can still be a list that gets elements added. One more thing... can you show me the benchmark code you did for ObjectRange as well? |
|
Yes, I changed the description to The |
|
@paplorinc Your changes crash the build http://ci.groovy-lang.org/viewLog.html?buildId=27049&tab=buildResultsDiv&buildTypeId=Groovy_Jdk7Build |
|
Thanks, will rerun it locally (can't view the TC build). |
|
@paplorinc You can view the tc build if you login as "guest" with a blank password. CI trigger for pull request would be very helpful (we had this before the move to apache), but I was told it's not possible with teamcity and the read-only apache github mirror. |
|
Thanks, the problem was, that in case of enums, at the boundaries, the |
07fb83d to
d1c57fd
Compare
|
|
d1c57fd to
5c87699
Compare
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.
5c87699 to
bcaa3ac
Compare
|
Since #143 was merged, this PR should be rebased, and some conflicts can be expected. |
|
Thanks, but I will rather abandon it at this stage. |
|
Possibly at least the increment/decrement optimization for numbers could be kept |
|
I copied out a few of the additional tests you added to cover existing functionality. Also, PRs #142 and #143 have been merged recently. It would be nice to incorporate a reworked version of this PR catering for those changes. If no-one else jumps in I'll take a look myself. Created this issue for tracking purposes: GROOVY-7877. |
|
I will rebase it, seeing that there is need for it :) |
|
Just for fun, I had a look at what a utility method outside of Range might look like: |
|
Revived in #360, please review. |
Until now a
Rangecould 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.9strange, as that resulted in a single element.Also, stepping over
ObjectRangeinstances (like the above one) called thenext/previousmethod 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
steptype toNumberand unified the way stepping is done inObjectRangeandIntRange, making them as fast as the originalIntRangefor numeric cases.Also,
IntRangetreats the overflow issue by storing the intermediary value in aLongdirectly.At the boundaries, the
nextandpreviousmethods may now wrap to the other extreme - or return null.I tested the speed via the following trivial method:
resulting in
and