提交 4452a4db authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Avoid allocation of two temporary arrays in Comparison.getAdditional()

上级 f1669ce2
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
package org.h2.expression.condition; package org.h2.expression.condition;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -575,25 +574,27 @@ public class Comparison extends Condition { ...@@ -575,25 +574,27 @@ public class Comparison extends Condition {
} }
} else { } else {
// a=b OR a=c // a=b OR a=c
Database db = session.getDatabase();
if (rc && r2c && l.equals(l2)) { if (rc && r2c && l.equals(l2)) {
return new ConditionIn(db, left, return getConditionIn(session, left, right, other.right);
new ArrayList<>(Arrays.asList(right, other.right)));
} else if (rc && l2c && l.equals(r2)) { } else if (rc && l2c && l.equals(r2)) {
return new ConditionIn(db, left, return getConditionIn(session, left, right, other.left);
new ArrayList<>(Arrays.asList(right, other.left)));
} else if (lc && r2c && r.equals(l2)) { } else if (lc && r2c && r.equals(l2)) {
return new ConditionIn(db, right, return getConditionIn(session, right, left, other.right);
new ArrayList<>(Arrays.asList(left, other.right)));
} else if (lc && l2c && r.equals(r2)) { } else if (lc && l2c && r.equals(r2)) {
return new ConditionIn(db, right, return getConditionIn(session, right, left, other.left);
new ArrayList<>(Arrays.asList(left, other.left)));
} }
} }
} }
return null; return null;
} }
private static ConditionIn getConditionIn(Session session, Expression left, Expression value1, Expression value2) {
ArrayList<Expression> right = new ArrayList<>(2);
right.add(value1);
right.add(value2);
return new ConditionIn(session.getDatabase(), left, right);
}
@Override @Override
public int getSubexpressionCount() { public int getSubexpressionCount() {
return compareType == IS_NULL || compareType == IS_NOT_NULL ? 1 : 2; return compareType == IS_NULL || compareType == IS_NOT_NULL ? 1 : 2;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论