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

SWinxy duke at openjdk.java.net
Fri May 6 15:45:49 UTC 2022


On Sat, 15 Jan 2022 04:23:33 GMT, SWinxy <duke at openjdk.java.net> 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.

I see... It's something similar to JOML's [FASTMATH](https://joml-ci.github.io/JOML/apidocs/org/joml/Options.html#FASTMATH) option.
Even if calling Math.min/max wouldn't be faster (I would hope so, being tagged with @IntrinsicCandidate), it would still be unnecessary code duplication. The Java code is identical, save for the `final` modifier in the parameter list.
`ceil_f`, `floor_f`, and `floor_int(float)` are not used.
`ceil_int(float)` is only used once, in `MarlinProperties.align`. `align` is used only three times, with the callers being constants in `MarlinConst`. This is to say the performance benefit would be pointless assuming the three callers to `align` aren't called in other peoples' code (I doubt, but who knows).
For `ceil_int(double)` and `floor_int(double)`, that is where performance would matter. What I can end up doing is adding back `FloatMath` with those two methods, and rename it to `FastMath` or something.

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

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



More information about the client-libs-dev mailing list