8074003: java.time.zone.ZoneRules.getOffset(java.time.Instant) can be optimized
Make epochSecond part of ZoneOffsetTransition so it doesn't have to be recomputed frequently Reviewed-by: scolebourne, rriggs
This commit is contained in:
parent
c565cf62f8
commit
b308a894cf
@ -103,6 +103,10 @@ public final class ZoneOffsetTransition
|
||||
* Serialization version.
|
||||
*/
|
||||
private static final long serialVersionUID = -6946044323557704546L;
|
||||
/**
|
||||
* The transition epoch-second.
|
||||
*/
|
||||
private final long epochSecond;
|
||||
/**
|
||||
* The local transition date-time at the transition.
|
||||
*/
|
||||
@ -152,6 +156,7 @@ public final class ZoneOffsetTransition
|
||||
* @param offsetAfter the offset at and after the transition, not null
|
||||
*/
|
||||
ZoneOffsetTransition(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) {
|
||||
this.epochSecond = transition.toEpochSecond(offsetBefore);
|
||||
this.transition = transition;
|
||||
this.offsetBefore = offsetBefore;
|
||||
this.offsetAfter = offsetAfter;
|
||||
@ -165,6 +170,7 @@ public final class ZoneOffsetTransition
|
||||
* @param offsetAfter the offset at and after the transition, not null
|
||||
*/
|
||||
ZoneOffsetTransition(long epochSecond, ZoneOffset offsetBefore, ZoneOffset offsetAfter) {
|
||||
this.epochSecond = epochSecond;
|
||||
this.transition = LocalDateTime.ofEpochSecond(epochSecond, 0, offsetBefore);
|
||||
this.offsetBefore = offsetBefore;
|
||||
this.offsetAfter = offsetAfter;
|
||||
@ -209,7 +215,7 @@ public final class ZoneOffsetTransition
|
||||
* @throws IOException if an error occurs
|
||||
*/
|
||||
void writeExternal(DataOutput out) throws IOException {
|
||||
Ser.writeEpochSec(toEpochSecond(), out);
|
||||
Ser.writeEpochSec(epochSecond, out);
|
||||
Ser.writeOffset(offsetBefore, out);
|
||||
Ser.writeOffset(offsetAfter, out);
|
||||
}
|
||||
@ -253,7 +259,7 @@ public final class ZoneOffsetTransition
|
||||
* @return the transition epoch second
|
||||
*/
|
||||
public long toEpochSecond() {
|
||||
return transition.toEpochSecond(offsetBefore);
|
||||
return epochSecond;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@ -397,7 +403,13 @@ public final class ZoneOffsetTransition
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(ZoneOffsetTransition transition) {
|
||||
return this.getInstant().compareTo(transition.getInstant());
|
||||
if (epochSecond < transition.epochSecond) {
|
||||
return -1;
|
||||
} else if (epochSecond > transition.epochSecond) {
|
||||
return 1;
|
||||
} else {
|
||||
return this.getInstant().compareTo(transition.getInstant());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -416,7 +428,8 @@ public final class ZoneOffsetTransition
|
||||
}
|
||||
if (other instanceof ZoneOffsetTransition) {
|
||||
ZoneOffsetTransition d = (ZoneOffsetTransition) other;
|
||||
return transition.equals(d.transition) &&
|
||||
return epochSecond == d.epochSecond &&
|
||||
transition.equals(d.transition) &&
|
||||
offsetBefore.equals(d.offsetBefore) && offsetAfter.equals(d.offsetAfter);
|
||||
}
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user