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