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 long epochSecondsInUTC;

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

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

@Override
Expand Down

0 comments on commit e04c5db

Please sign in to comment.