mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8310241: OffsetDateTime compareTo redundant computation
Reviewed-by: naoto
This commit is contained in:
parent
d97966266e
commit
11fd34e196
2 changed files with 9 additions and 2 deletions
|
@ -1805,7 +1805,13 @@ public final class OffsetDateTime
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(OffsetDateTime other) {
|
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) {
|
if (cmp == 0) {
|
||||||
cmp = toLocalDateTime().compareTo(other.toLocalDateTime());
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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(a.compareTo(a) == 0, true);
|
||||||
assertEquals(b.compareTo(b) == 0, true);
|
assertEquals(b.compareTo(b) == 0, true);
|
||||||
assertEquals(a.toInstant().compareTo(b.toInstant()) == 0, true);
|
assertEquals(a.toInstant().compareTo(b.toInstant()) == 0, true);
|
||||||
|
assertEquals(OffsetDateTime.timeLineOrder().compare(a,b) == 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue