提交 c940fbb4 authored 作者: Thomas Mueller's avatar Thomas Mueller

Small improvements.

上级 aa455b32
...@@ -317,7 +317,7 @@ public abstract class Expression { ...@@ -317,7 +317,7 @@ public abstract class Expression {
public static Expression[] getExpressionColumns(Session session, ValueArray value) { public static Expression[] getExpressionColumns(Session session, ValueArray value) {
Value[] list = value.getList(); Value[] list = value.getList();
ExpressionColumn[] expr = new ExpressionColumn[list.length]; ExpressionColumn[] expr = new ExpressionColumn[list.length];
for (int i = 0; i < list.length; i++) { for (int i = 0, len = list.length; i < len; i++) {
Value v = list[i]; Value v = list[i];
Column col = new Column("C" + (i + 1), v.getType(), v.getPrecision(), v.getScale(), Column col = new Column("C" + (i + 1), v.getType(), v.getPrecision(), v.getScale(),
v.getDisplaySize()); v.getDisplaySize());
......
...@@ -99,16 +99,17 @@ public class JavaAggregate extends Expression { ...@@ -99,16 +99,17 @@ public class JavaAggregate extends Expression {
} }
public void mapColumns(ColumnResolver resolver, int level) { public void mapColumns(ColumnResolver resolver, int level) {
for (int i = 0; i < args.length; i++) { for (Expression arg : args) {
args[i].mapColumns(resolver, level); arg.mapColumns(resolver, level);
} }
} }
public Expression optimize(Session session) { public Expression optimize(Session session) {
userConnection = session.createConnection(false); userConnection = session.createConnection(false);
argTypes = new int[args.length]; int len = args.length;
int[] argSqlTypes = new int[args.length]; argTypes = new int[len];
for (int i = 0; i < args.length; i++) { int[] argSqlTypes = new int[len];
for (int i = 0; i < len; i++) {
Expression expr = args[i]; Expression expr = args[i];
args[i] = expr.optimize(session); args[i] = expr.optimize(session);
int type = expr.getType(); int type = expr.getType();
...@@ -178,7 +179,7 @@ public class JavaAggregate extends Expression { ...@@ -178,7 +179,7 @@ public class JavaAggregate extends Expression {
} }
Object[] argValues = new Object[args.length]; Object[] argValues = new Object[args.length];
Object arg = null; Object arg = null;
for (int i = 0; i < args.length; i++) { for (int i = 0, len = args.length; i < len; i++) {
Value v = args[i].getValue(session); Value v = args[i].getValue(session);
v = v.convertTo(argTypes[i]); v = v.convertTo(argTypes[i]);
arg = v.getObject(); arg = v.getObject();
......
...@@ -53,7 +53,7 @@ public class JavaFunction extends Expression implements FunctionCall { ...@@ -53,7 +53,7 @@ public class JavaFunction extends Expression implements FunctionCall {
public Expression optimize(Session session) { public Expression optimize(Session session) {
boolean allConst = isDeterministic(); boolean allConst = isDeterministic();
for (int i = 0; i < args.length; i++) { for (int i = 0, len = args.length; i < len; i++) {
Expression e = args[i].optimize(session); Expression e = args[i].optimize(session);
args[i] = e; args[i] = e;
allConst &= e.isConstant(); allConst &= e.isConstant();
...@@ -160,9 +160,9 @@ public class JavaFunction extends Expression implements FunctionCall { ...@@ -160,9 +160,9 @@ public class JavaFunction extends Expression implements FunctionCall {
public Expression[] getExpressionColumns(Session session) { public Expression[] getExpressionColumns(Session session) {
switch (getType()) { switch (getType()) {
case Value.RESULT_SET: case Value.RESULT_SET:
ValueResultSet vrs = getValueForColumnList(session, getArgs()); ValueResultSet rs = getValueForColumnList(session, getArgs());
try { try {
return getExpressionColumns(session, vrs.getResultSet()); return getExpressionColumns(session, rs.getResultSet());
} catch (SQLException e) { } catch (SQLException e) {
throw DbException.convert(e); throw DbException.convert(e);
} }
......
...@@ -96,14 +96,14 @@ public class Subquery extends Expression { ...@@ -96,14 +96,14 @@ public class Subquery extends Expression {
private Expression getExpression() { private Expression getExpression() {
if (expression == null) { if (expression == null) {
ArrayList<Expression> exprs = query.getExpressions(); ArrayList<Expression> expressions = query.getExpressions();
int columnCount = query.getColumnCount(); int columnCount = query.getColumnCount();
if (columnCount == 1) { if (columnCount == 1) {
expression = exprs.get(0); expression = expressions.get(0);
} else { } else {
Expression[] list = new Expression[columnCount]; Expression[] list = new Expression[columnCount];
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
list[i] = exprs.get(i); list[i] = expressions.get(i);
} }
expression = new ExpressionList(list); expression = new ExpressionList(list);
} }
......
...@@ -961,8 +961,7 @@ public class FullText { ...@@ -961,8 +961,7 @@ public class FullText {
private int[] getWordIds(Object[] row) throws SQLException { private int[] getWordIds(Object[] row) throws SQLException {
HashSet<String> words = New.hashSet(); HashSet<String> words = New.hashSet();
for (int i = 0; i < index.indexColumns.length; i++) { for (int idx : index.indexColumns) {
int idx = index.indexColumns[i];
int type = columnTypes[idx]; int type = columnTypes[idx];
Object data = row[idx]; Object data = row[idx];
if (type == Types.CLOB && data != null) { if (type == Types.CLOB && data != null) {
......
...@@ -430,8 +430,9 @@ public class FullTextLucene extends FullText { ...@@ -430,8 +430,9 @@ public class FullTextLucene extends FullText {
if (limit == 0) { if (limit == 0) {
limit = docs.totalHits; limit = docs.totalHits;
} }
for (int i = 0; i < limit && i + offset < docs.totalHits for (int i = 0, len = docs.scoreDocs.length;
&& i + offset < docs.scoreDocs.length; i++) { i < limit && i + offset < docs.totalHits
&& i + offset < len; i++) {
ScoreDoc sd = docs.scoreDocs[i + offset]; ScoreDoc sd = docs.scoreDocs[i + offset];
Document doc = searcher.doc(sd.doc); Document doc = searcher.doc(sd.doc);
float score = sd.score; float score = sd.score;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论