提交 97efe575 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Do not call getSQL() more than once for each expression in optimizeConditionAndOr()

上级 508f61cf
......@@ -319,25 +319,30 @@ public class ConditionAndOr extends Condition {
* @param right the second condition
* @return null or the third condition
*/
private Expression optimizeConditionAndOr(ConditionAndOr left, ConditionAndOr right) {
private static Expression optimizeConditionAndOr(ConditionAndOr left, ConditionAndOr right) {
if (left.andOrType != AND || right.andOrType != AND) {
return null;
}
Expression commonExpressionLeft = left.getSubexpression(0);
Expression commonExpressionRight = left.getSubexpression(1);
Expression leftLeft = left.getSubexpression(0), leftRight = left.getSubexpression(1);
Expression rightLeft = right.getSubexpression(0), rightRight = right.getSubexpression(1);
String leftLeftSQL = leftLeft.getSQL(), rightLeftSQL = rightLeft.getSQL();
Expression combinedExpression;
if (left.getSubexpression(0).getSQL().equals(right.getSubexpression(0).getSQL())) {
combinedExpression = new ConditionAndOr(OR, left.getSubexpression(1), right.getSubexpression(1));
return new ConditionAndOr(AND, commonExpressionLeft, combinedExpression);
} else if (left.getSubexpression(0).getSQL().equals(right.getSubexpression(1).getSQL())) {
combinedExpression = new ConditionAndOr(OR, left.getSubexpression(1), right.getSubexpression(0));
return new ConditionAndOr(AND, commonExpressionLeft, combinedExpression);
} else if (left.getSubexpression(1).getSQL().equals(right.getSubexpression(0).getSQL())) {
combinedExpression = new ConditionAndOr(OR, left.getSubexpression(0), right.getSubexpression(1));
return new ConditionAndOr(AND, commonExpressionRight, combinedExpression);
} else if (left.getSubexpression(1).getSQL().equals(right.getSubexpression(1).getSQL())) {
combinedExpression = new ConditionAndOr(OR, left.getSubexpression(0), right.getSubexpression(0));
return new ConditionAndOr(AND, commonExpressionRight, combinedExpression);
if (leftLeftSQL.equals(rightLeftSQL)) {
combinedExpression = new ConditionAndOr(OR, leftRight, rightRight);
return new ConditionAndOr(AND, leftLeft, combinedExpression);
}
String rightRightSQL = rightRight.getSQL();
if (leftLeftSQL.equals(rightRightSQL)) {
combinedExpression = new ConditionAndOr(OR, leftRight, rightLeft);
return new ConditionAndOr(AND, leftLeft, combinedExpression);
}
String leftRightSQL = leftRight.getSQL();
if (leftRightSQL.equals(rightLeftSQL)) {
combinedExpression = new ConditionAndOr(OR, leftLeft, rightRight);
return new ConditionAndOr(AND, leftRight, combinedExpression);
} else if (leftRightSQL.equals(rightRightSQL)) {
combinedExpression = new ConditionAndOr(OR, leftLeft, rightLeft);
return new ConditionAndOr(AND, leftRight, combinedExpression);
}
return null;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论