RFR: 8286271: [java.desktop] Replace ternary operators with java.lang.Math min/max

SWinxy duke at openjdk.java.net
Fri May 6 23:52:36 UTC 2022


On Fri, 6 May 2022 16:52:47 GMT, Laurent Bourgès <lbourges at openjdk.org> wrote:

>> Delete `sun.java2d.marlin.FloatMath` class in favor of methods in `java.lang.Math`. The methods in `Math.java` are intrinsics and can gain from significant speedups. Hand-written min/max operations are also replaced with calls. 5 uses of `ceil` and 2 uses of `floor` were replaced.
>> This should not cause any rendering differences from the different algorithms being used, as they theoretically will end up at the same outcomes.
>
> Please keep FloatMath alive to have floor/ceil (double) and I will anyway merge in my repo.
> Go on

Say the `Double.compare` change is dropped (makes sense; the method is not the same as the replaced code), the changes to RowFilter are undone (i.e. `abs()`), and the performance-critical code @bourgesl wants is kept. This leaves the ternary operators and FloatMath as changed. Does the risk of regression make readability improvements unworthy? Take this line for instance:

int y = (itemBounds.y + itemBounds.height > screenBounds.y) ? itemBounds.y + itemBounds.height : screenBounds.y; // from
int y = Math.max(itemBounds.y + itemBounds.height, screenBounds.y); // to

I get that you're cautious, but this is more understandable to maintain. It takes much effort to really understand what the ternary operators are doing, and I believe that it is worth changing.

-------------

PR: https://git.openjdk.java.net/jdk/pull/7097



More information about the client-libs-dev mailing list