8310241: OffsetDateTime compareTo redundant computation
Reviewed-by: naoto
This commit is contained in:
parent
d97966266e
commit
11fd34e196
src/java.base/share/classes/java/time
test/jdk/java/time/tck/java/time
@ -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());
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -1381,6 +1381,7 @@ public class TCKOffsetDateTime extends AbstractDateTimeTest {
|
||||
assertEquals(a.compareTo(a) == 0, true);
|
||||
assertEquals(b.compareTo(b) == 0, true);
|
||||
assertEquals(a.toInstant().compareTo(b.toInstant()) == 0, true);
|
||||
assertEquals(OffsetDateTime.timeLineOrder().compare(a,b) == 0, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user