RFR: 8310241: OffsetDateTime compareTo redundant computation

Roger Riggs rriggs at openjdk.org
Thu Jun 22 19:10:16 UTC 2023


Remove a redundant comparison in java.time `OffsetDateTime.compareTo()`. 
If the `compareInstant` utility method returns 0 (equal), it compares the `LocalDateTime`.
However, `compareInstant` has already done that comparison; if it found equal, the `compareTo` method unnecessarily does it again.
The code is refactored in `compareInstant` to do the comparison of `LocalDateTime` exactly once, if it is needed.

This case is covered by existing tests in test/jdk/java/time/tck/java/time/TCKOffsetDateTime.java

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

Commit messages:
 - 8310241: OffsetDateTime compareTo redundant computation

Changes: https://git.openjdk.org/jdk/pull/14618/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14618&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8310241
  Stats: 19 lines in 1 file changed: 10 ins; 5 del; 4 mod
  Patch: https://git.openjdk.org/jdk/pull/14618.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/14618/head:pull/14618

PR: https://git.openjdk.org/jdk/pull/14618


More information about the core-libs-dev mailing list