RFR: 8286163: micro-optimize Instant.plusSeconds

Claes Redestad redestad at openjdk.java.net
Sun May 8 22:43:36 UTC 2022


On Fri, 6 May 2022 22:02:58 GMT, Stephen Colebourne <scolebourne at openjdk.org> wrote:

> Seems reasonable to me. plus(long, long) already has this optimisation.

If it already had this optimization then why change anything? I think you're referring to the check for `0` to return `this` then that is something `plusSeconds` will need to retain for parity. The optimization here appears to be the avoiding of added arithmetic for dealing with nanoseconds. And though it bothers me that the JIT doesn't optimize this better (given that the nanosecond parameter to `plus(long, long)` is a constant zero) the patch does seem reasonable.

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

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


More information about the core-libs-dev mailing list