From 079964029903db37b2a3dad454491f5deee0a22e Mon Sep 17 00:00:00 2001 From: Navis Ryu Date: Wed, 26 Oct 2016 17:50:27 +0900 Subject: [PATCH] Faster interval comparator (#3605) --- .../druid/java/util/common/guava/Comparators.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/java-util/src/main/java/io/druid/java/util/common/guava/Comparators.java b/java-util/src/main/java/io/druid/java/util/common/guava/Comparators.java index 6dac80b2f7f..4b05f71a861 100644 --- a/java-util/src/main/java/io/druid/java/util/common/guava/Comparators.java +++ b/java-util/src/main/java/io/druid/java/util/common/guava/Comparators.java @@ -19,6 +19,7 @@ package io.druid.java.util.common.guava; +import com.google.common.primitives.Longs; import org.joda.time.DateTimeComparator; import org.joda.time.Interval; @@ -74,6 +75,13 @@ public class Comparators @Override public int compare(Interval lhs, Interval rhs) { + if (lhs.getChronology().equals(rhs.getChronology())) { + int compare = Longs.compare(lhs.getStartMillis(), rhs.getStartMillis()); + if (compare == 0) { + return Longs.compare(lhs.getEndMillis(), rhs.getEndMillis()); + } + return compare; + } int retVal = dateTimeComp.compare(lhs.getStart(), rhs.getStart()); if (retVal == 0) { retVal = dateTimeComp.compare(lhs.getEnd(), rhs.getEnd()); @@ -89,6 +97,13 @@ public class Comparators @Override public int compare(Interval lhs, Interval rhs) { + if (lhs.getChronology().equals(rhs.getChronology())) { + int compare = Longs.compare(lhs.getEndMillis(), rhs.getEndMillis()); + if (compare == 0) { + return Longs.compare(lhs.getStartMillis(), rhs.getStartMillis()); + } + return compare; + } int retVal = dateTimeComp.compare(lhs.getEnd(), rhs.getEnd()); if (retVal == 0) { retVal = dateTimeComp.compare(lhs.getStart(), rhs.getStart());