8286163: micro-optimize Instant.plusSeconds

Reviewed-by: scolebourne, redestad, naoto
This commit is contained in:
Lennart Fricke 2022-05-10 09:00:09 +00:00 committed by Claes Redestad
parent 60a91d15ad
commit 3462190965
2 changed files with 94 additions and 1 deletions

View file

@ -878,7 +878,11 @@ public final class Instant
* @throws ArithmeticException if numeric overflow occurs
*/
public Instant plusSeconds(long secondsToAdd) {
return plus(secondsToAdd, 0);
if (secondsToAdd == 0) {
return this;
}
long epochSec = Math.addExact(seconds, secondsToAdd);
return create(epochSec, nanos);
}
/**