ARTEMIS-3962 porting changes from AMQ-9052

Optimisations to improve the efficiency of the selectors.
This commit is contained in:
Justin Bertram 2022-08-29 14:28:06 -05:00
parent 9d20d7b87f
commit f0ff385c7c
No known key found for this signature in database
GPG Key ID: F41830B875BB8633
2 changed files with 35 additions and 0 deletions

View File

@ -232,6 +232,31 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
return Boolean.FALSE;
}
@Override
public boolean matches(Filterable message) throws FilterException {
Object lv = left.evaluate(message);
Object rv = right.evaluate(message);
// If one of the values is null
if (lv == null ^ rv == null) {
return false;
}
if (lv == rv || lv.equals(rv)) {
return true;
}
if (lv.getClass() == rv.getClass()) {
// same class, but 'equals' return false, and they are not the same object
// there is no point in doing 'compare'
// this case happens often while comparing non equals Strings
return false;
}
if (lv instanceof Comparable && rv instanceof Comparable) {
Boolean compareResult = compare((Comparable) lv, (Comparable) rv);
return compareResult != null && compareResult;
}
return false;
}
@Override
protected boolean asBoolean(int answer) {
return answer == 0;

View File

@ -139,6 +139,16 @@ public abstract class UnaryExpression implements Expression {
return !lvalue.booleanValue();
}
@Override
public boolean matches(Filterable message) throws FilterException {
Boolean lvalue = (Boolean) right.evaluate(message);
if (lvalue == null) {
// NOT NULL returns NULL that eventually fails the selector
return false;
}
return !lvalue;
}
@Override
public String getExpressionSymbol() {
return "NOT";