Skip to content

Commit

Permalink
Compare LocalDateTimes faster by pre-computing epochSecond.
Browse files Browse the repository at this point in the history
  • Loading branch information
sherfert committed Mar 23, 2018
1 parent 2887607 commit e04c5db
Showing 1 changed file with 10 additions and 3 deletions.
Expand Up @@ -263,17 +263,24 @@ protected LocalDateTimeValue selectDateTime( AnyValue datetime )
} }


private final LocalDateTime value; private final LocalDateTime value;
private final long epochSecondsInUTC;


private LocalDateTimeValue( LocalDateTime value ) private LocalDateTimeValue( LocalDateTime value )
{ {
this.value = value; this.value = value;
this.epochSecondsInUTC = this.value.toEpochSecond(UTC);
} }


@Override @Override
int unsafeCompareTo( Value otherValue ) int unsafeCompareTo( Value other )
{ {
LocalDateTimeValue other = (LocalDateTimeValue) otherValue; LocalDateTimeValue that = (LocalDateTimeValue) other;
return value.compareTo( other.value ); int cmp = Long.compare( epochSecondsInUTC, that.epochSecondsInUTC );
if ( cmp == 0 )
{
cmp = value.getNano() - that.value.getNano();
}
return cmp;
} }


@Override @Override
Expand Down

0 comments on commit e04c5db

Please sign in to comment.