BoundDimFilter: Simplify the various DruidLongPredicates. (#10906)

They all use Long.compare, but they don't need to. Changing to
regular comparisons simplifies the code and also removes branches.
(Internally, Long.compare has two branches.)
This commit is contained in:
Gian Merlino 2021-02-19 16:44:56 -08:00 committed by GitHub
parent f5bfccc720
commit b7e9f5bc85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 76 deletions

View File

@ -615,93 +615,25 @@ public class BoundDimFilter extends AbstractOptimizableDimFilter implements DimF
{ {
if (hasLowerLongBound && hasUpperLongBound) { if (hasLowerLongBound && hasUpperLongBound) {
if (upperStrict && lowerStrict) { if (upperStrict && lowerStrict) {
return new DruidLongPredicate() return input -> input > lowerLongBound && input < upperLongBound;
{
@Override
public boolean applyLong(long input)
{
final int lowerComparing = Long.compare(input, lowerLongBound);
final int upperComparing = Long.compare(upperLongBound, input);
return ((lowerComparing > 0)) && (upperComparing > 0);
}
};
} else if (lowerStrict) { } else if (lowerStrict) {
return new DruidLongPredicate() return input -> input > lowerLongBound && input <= upperLongBound;
{
@Override
public boolean applyLong(long input)
{
final int lowerComparing = Long.compare(input, lowerLongBound);
final int upperComparing = Long.compare(upperLongBound, input);
return (lowerComparing > 0) && (upperComparing >= 0);
}
};
} else if (upperStrict) { } else if (upperStrict) {
return new DruidLongPredicate() return input -> input >= lowerLongBound && input < upperLongBound;
{
@Override
public boolean applyLong(long input)
{
final int lowerComparing = Long.compare(input, lowerLongBound);
final int upperComparing = Long.compare(upperLongBound, input);
return (lowerComparing >= 0) && (upperComparing > 0);
}
};
} else { } else {
return new DruidLongPredicate() return input -> input >= lowerLongBound && input <= upperLongBound;
{
@Override
public boolean applyLong(long input)
{
final int lowerComparing = Long.compare(input, lowerLongBound);
final int upperComparing = Long.compare(upperLongBound, input);
return (lowerComparing >= 0) && (upperComparing >= 0);
}
};
} }
} else if (hasUpperLongBound) { } else if (hasUpperLongBound) {
if (upperStrict) { if (upperStrict) {
return new DruidLongPredicate() return input -> input < upperLongBound;
{
@Override
public boolean applyLong(long input)
{
final int upperComparing = Long.compare(upperLongBound, input);
return upperComparing > 0;
}
};
} else { } else {
return new DruidLongPredicate() return input -> input <= upperLongBound;
{
@Override
public boolean applyLong(long input)
{
final int upperComparing = Long.compare(upperLongBound, input);
return upperComparing >= 0;
}
};
} }
} else if (hasLowerLongBound) { } else if (hasLowerLongBound) {
if (lowerStrict) { if (lowerStrict) {
return new DruidLongPredicate() return input -> input > lowerLongBound;
{
@Override
public boolean applyLong(long input)
{
final int lowerComparing = Long.compare(input, lowerLongBound);
return lowerComparing > 0;
}
};
} else { } else {
return new DruidLongPredicate() return input -> input >= lowerLongBound;
{
@Override
public boolean applyLong(long input)
{
final int lowerComparing = Long.compare(input, lowerLongBound);
return lowerComparing >= 0;
}
};
} }
} else { } else {
return DruidLongPredicate.ALWAYS_TRUE; return DruidLongPredicate.ALWAYS_TRUE;