8310241: OffsetDateTime compareTo redundant computation

Reviewed-by: naoto
This commit is contained in:
Roger Riggs 2023-06-29 21:05:37 +00:00
parent d97966266e
commit 11fd34e196
2 changed files with 9 additions and 2 deletions

View file

@ -1805,7 +1805,13 @@ public final class OffsetDateTime
*/
@Override
public int compareTo(OffsetDateTime other) {
int cmp = compareInstant(this, other);
int cmp = getOffset().compareTo(other.getOffset());
if (cmp != 0) {
cmp = Long.compare(toEpochSecond(), other.toEpochSecond());
if (cmp == 0) {
cmp = toLocalTime().getNano() - other.toLocalTime().getNano();
}
}
if (cmp == 0) {
cmp = toLocalDateTime().compareTo(other.toLocalDateTime());
}