RFR: 8310241: OffsetDateTime compareTo redundant computation [v2]

Roger Riggs rriggs at openjdk.org
Wed Jun 28 17:46:51 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 `compareTo` to do the comparison of `LocalDateTime` exactly once, if it is needed.
> 
> This case is NOT covered by an existing test in test/jdk/java/time/tck/java/time/TCKOffsetDateTime.java

Roger Riggs has updated the pull request incrementally with one additional commit since the last revision:

  Reopen to work on an improved fix
  Add a test for the specific condition being optimized, the test was missing in the original.

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/14618/files
  - new: https://git.openjdk.org/jdk/pull/14618/files/a5fcbd0a..352a3fae

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=14618&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=14618&range=00-01

  Stats: 27 lines in 2 files changed: 12 ins; 10 del; 5 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