提交 645494c4 authored 作者: Thomas Mueller's avatar Thomas Mueller

Smaller changes (mainly for Android).

上级 6969ad47
......@@ -429,7 +429,7 @@ public class Parser {
throw getSyntaxError();
}
if (indexedParameterList != null) {
for (int i = 0; i < indexedParameterList.size(); i++) {
for (int i = 0, size = indexedParameterList.size(); i < size; i++) {
if (indexedParameterList.get(i) == null) {
indexedParameterList.set(i, new Parameter(i));
}
......@@ -844,9 +844,11 @@ public class Parser {
private Prepared prepare(Session s, String sql, ArrayList<Value> paramValues) {
Prepared prep = s.prepare(sql);
ArrayList<Parameter> params = prep.getParameters();
for (int i = 0; params != null && i < params.size(); i++) {
Parameter p = params.get(i);
p.setValue(paramValues.get(i));
if (params != null) {
for (int i = 0, size = params.size(); i < size; i++) {
Parameter p = params.get(i);
p.setValue(paramValues.get(i));
}
}
return prep;
}
......@@ -955,11 +957,7 @@ public class Parser {
if (isSelect()) {
Query query = parseSelectUnion();
read(")");
ArrayList<Parameter> params = New.arrayList();
for (int i = 0; i < parameters.size(); i++) {
params.add(parameters.get(i));
}
query.setParameterList(params);
query.setParameterList(New.arrayList(parameters));
query.init();
Session s;
if (createView != null) {
......@@ -1404,7 +1402,7 @@ public class Parser {
int paramIndex = parameters.size();
Query command = parseSelectUnion();
ArrayList<Parameter> params = New.arrayList();
for (int i = paramIndex; i < parameters.size(); i++) {
for (int i = paramIndex, size = parameters.size(); i < size; i++) {
params.add(parameters.get(i));
}
command.setParameterList(params);
......@@ -5053,7 +5051,7 @@ public class Parser {
if ((!Character.isLetter(c) && c != '_') || Character.isLowerCase(c)) {
return StringUtils.quoteIdentifier(s);
}
for (int i = 0; i < s.length(); i++) {
for (int i = 1, length = s.length(); i < length; i++) {
c = s.charAt(i);
if ((!Character.isLetterOrDigit(c) && c != '_') || Character.isLowerCase(c)) {
return StringUtils.quoteIdentifier(s);
......
......@@ -156,9 +156,11 @@ public abstract class Prepared {
* @throws SQLException if any parameter has not been set
*/
protected void checkParameters() {
for (int i = 0; parameters != null && i < parameters.size(); i++) {
Parameter param = parameters.get(i);
param.checkSet();
if (parameters != null) {
for (int i = 0, size = parameters.size(); i < size; i++) {
Parameter param = parameters.get(i);
param.checkSet();
}
}
}
......
......@@ -85,11 +85,11 @@ public class Merge extends Prepared {
session.setLastIdentity(ValueLong.get(0));
if (list.size() > 0) {
count = 0;
for (int x = 0; x < list.size(); x++) {
for (int x = 0, size = list.size(); x < size; x++) {
setCurrentRowNumber(x + 1);
Expression[] expr = list.get(x);
Row newRow = table.getTemplateRow();
for (int i = 0; i < columns.length; i++) {
for (int i = 0, len = columns.length; i < len; i++) {
Column c = columns[i];
int index = c.getColumnId();
Expression e = expr[i];
......
......@@ -214,8 +214,9 @@ public abstract class Query extends Prepared {
if (list == null) {
list = New.arrayList();
}
Value[] params = new Value[list.size()];
for (int i = 0; i < list.size(); i++) {
int size = list.size();
Value[] params = new Value[size];
for (int i = 0; i < size; i++) {
Value v = list.get(i).getParamValue();
params[i] = v;
}
......@@ -330,12 +331,14 @@ public abstract class Query extends Prepared {
}
} else {
String s = e.getSQL();
for (int j = 0; expressionSQL != null && j < expressionSQL.size(); j++) {
String s2 = expressionSQL.get(j);
if (s2.equals(s)) {
idx = j;
isAlias = true;
break;
if (expressionSQL != null) {
for (int j = 0, size = expressionSQL.size(); j < size; j++) {
String s2 = expressionSQL.get(j);
if (s2.equals(s)) {
idx = j;
isAlias = true;
break;
}
}
}
}
......@@ -360,9 +363,10 @@ public abstract class Query extends Prepared {
* @return the {@link SortOrder} object
*/
public SortOrder prepareOrder(ArrayList<SelectOrderBy> orderList, int expressionCount) {
int[] index = new int[orderList.size()];
int[] sortType = new int[orderList.size()];
for (int i = 0; i < orderList.size(); i++) {
int size = orderList.size();
int[] index = new int[size];
int[] sortType = new int[size];
for (int i = 0; i < size; i++) {
SelectOrderBy o = orderList.get(i);
int idx;
boolean reverse = false;
......
......@@ -238,13 +238,15 @@ public class Select extends Query {
return null;
}
ArrayList<Index> indexes = topTableFilter.getTable().getIndexes();
for (int i = 0; indexes != null && i < indexes.size(); i++) {
Index index = indexes.get(i);
if (index.getIndexType().isScan()) {
continue;
}
if (isGroupSortedIndex(topTableFilter, index)) {
return index;
if (indexes != null) {
for (int i = 0, size = indexes.size(); i < size; i++) {
Index index = indexes.get(i);
if (index.getIndexType().isScan()) {
continue;
}
if (isGroupSortedIndex(topTableFilter, index)) {
return index;
}
}
}
return null;
......@@ -256,7 +258,7 @@ public class Select extends Query {
// also check that the first columns in the index are grouped
boolean[] grouped = new boolean[indexColumns.length];
outerLoop:
for (int i = 0; i < expressions.size(); i++) {
for (int i = 0, size = expressions.size(); i < size; i++) {
if (!groupByExpression[i]) {
continue;
}
......@@ -407,38 +409,40 @@ public class Select extends Query {
return topTableFilter.getTable().getScanIndex(session);
}
ArrayList<Index> list = topTableFilter.getTable().getIndexes();
for (int i = 0; list != null && i < list.size(); i++) {
Index index = list.get(i);
if (index.getCreateSQL() == null) {
// can't use the scan index
continue;
}
if (index.getIndexType().isHash()) {
continue;
}
IndexColumn[] indexCols = index.getIndexColumns();
if (indexCols.length < sortCols.length) {
continue;
}
boolean ok = true;
for (int j = 0; j < sortCols.length; j++) {
// the index and the sort order must start
// with the exact same columns
IndexColumn idxCol = indexCols[j];
Column sortCol = sortCols[j];
if (idxCol.column != sortCol) {
ok = false;
break;
if (list != null) {
for (int i = 0, size = list.size(); i < size; i++) {
Index index = list.get(i);
if (index.getCreateSQL() == null) {
// can't use the scan index
continue;
}
if (idxCol.sortType != sortTypes[j]) {
// NULL FIRST for ascending and NULLS LAST
// for descending would actually match the default
ok = false;
break;
if (index.getIndexType().isHash()) {
continue;
}
IndexColumn[] indexCols = index.getIndexColumns();
if (indexCols.length < sortCols.length) {
continue;
}
boolean ok = true;
for (int j = 0; j < sortCols.length; j++) {
// the index and the sort order must start
// with the exact same columns
IndexColumn idxCol = indexCols[j];
Column sortCol = sortCols[j];
if (idxCol.column != sortCol) {
ok = false;
break;
}
if (idxCol.sortType != sortTypes[j]) {
// NULL FIRST for ascending and NULLS LAST
// for descending would actually match the default
ok = false;
break;
}
}
if (ok) {
return index;
}
}
if (ok) {
return index;
}
}
return null;
......@@ -617,6 +621,7 @@ public class Select extends Query {
}
private void expandColumnList() {
// the expressions may change within the loop
for (int i = 0; i < expressions.size(); i++) {
Expression expr = expressions.get(i);
if (!expr.isWildcard()) {
......@@ -696,12 +701,14 @@ public class Select extends Query {
// then 'HAVING' expressions,
// and 'GROUP BY' expressions at the end
if (group != null) {
groupIndex = new int[group.size()];
for (int i = 0; i < group.size(); i++) {
int size = group.size();
int expSize = expressionSQL.size();
groupIndex = new int[size];
for (int i = 0; i < size; i++) {
Expression expr = group.get(i);
String sql = expr.getSQL();
int found = -1;
for (int j = 0; j < expressionSQL.size(); j++) {
for (int j = 0; j < expSize; j++) {
String s2 = expressionSQL.get(j);
if (s2.equals(sql)) {
found = j;
......@@ -710,7 +717,7 @@ public class Select extends Query {
}
if (found < 0) {
// special case: GROUP BY a column alias
for (int j = 0; j < expressionSQL.size(); j++) {
for (int j = 0; j < expSize; j++) {
Expression e = expressions.get(j);
if (sql.equals(e.getAlias())) {
found = j;
......
......@@ -631,6 +631,7 @@ public class Session extends SessionWithState {
// MVCC: keep shared locks (insert / update / delete)
return;
}
// locks is modified in the loop
for (int i = 0; i < locks.size(); i++) {
Table t = locks.get(i);
if (!t.isLockedExclusively()) {
......@@ -661,7 +662,7 @@ public class Session extends SessionWithState {
if (locks.size() > 0) {
synchronized (database) {
// don't use the enhance for loop to safe memory
for (int i = 0; i < locks.size(); i++) {
for (int i = 0, size = locks.size(); i < size; i++) {
Table t = locks.get(i);
t.unlock(this);
}
......
......@@ -548,10 +548,12 @@ public class Aggregate extends Expression {
if (separator != null && !separator.isEverything(visitor)) {
return false;
}
for (int i = 0; orderList != null && i < orderList.size(); i++) {
SelectOrderBy o = orderList.get(i);
if (!o.expression.isEverything(visitor)) {
return false;
if (orderList != null) {
for (int i = 0, size = orderList.size(); i < size; i++) {
SelectOrderBy o = orderList.get(i);
if (!o.expression.isEverything(visitor)) {
return false;
}
}
}
return true;
......
......@@ -81,7 +81,8 @@ public class ConditionIn extends Condition {
return left;
}
boolean allValuesConstant = true;
for (int i = 0; i < valueList.size(); i++) {
int size = valueList.size();
for (int i = 0; i < size; i++) {
Expression e = valueList.get(i);
e = e.optimize(session);
if (allValuesConstant && !e.isConstant()) {
......@@ -92,7 +93,7 @@ public class ConditionIn extends Condition {
if (constant && allValuesConstant) {
return ValueExpression.get(getValue(session));
}
if (valueList.size() == 1) {
if (size == 1) {
Expression right = valueList.get(0);
Expression expr = new Comparison(session, Comparison.EQUAL, left, right);
expr = expr.optimize(session);
......
......@@ -146,7 +146,7 @@ public class Function extends Expression implements FunctionCall {
// SOUNDEX_INDEX
String index = "7AEIOUY8HW1BFPV2CGJKQSXZ3DT4L5MN6R";
char number = 0;
for (int i = 0; i < index.length(); i++) {
for (int i = 0, length = index.length(); i < length; i++) {
char c = index.charAt(i);
if (c < '9') {
number = c;
......
......@@ -73,7 +73,7 @@ public class IndexCursor implements Cursor {
inResult = null;
inResultTested = null;
// don't use enhanced for loop to avoid creating objects
for (int i = 0; i < indexConditions.size(); i++) {
for (int i = 0, size = indexConditions.size(); i < size; i++) {
IndexCondition condition = indexConditions.get(i);
if (condition.isAlwaysFalse()) {
alwaysFalse = true;
......
......@@ -195,11 +195,13 @@ public class ViewIndex extends BaseIndex {
return new ViewCursor(table, result);
}
ArrayList<Parameter> paramList = query.getParameters();
for (int i = 0; originalParameters != null && i < originalParameters.size(); i++) {
Parameter orig = originalParameters.get(i);
int idx = orig.getIndex();
Value value = orig.getValue(session);
setParameter(paramList, idx, value);
if (originalParameters != null) {
for (int i = 0, size = originalParameters.size(); i < size; i++) {
Parameter orig = originalParameters.get(i);
int idx = orig.getIndex();
Value value = orig.getValue(session);
setParameter(paramList, idx, value);
}
}
int len;
if (first != null) {
......
......@@ -92,7 +92,7 @@ public class RowList {
}
Data buff = rowBuff;
initBuffer(buff);
for (int i = 0; i < list.size(); i++) {
for (int i = 0, size = list.size(); i < size; i++) {
if (i > 0 && buff.length() > Constants.IO_BUFFER_SIZE) {
flushBuffer(buff);
initBuffer(buff);
......
......@@ -64,7 +64,7 @@ public class SHA256 {
String user = userName + "@";
byte[] buff = new byte[2 * (user.length() + password.length)];
int n = 0;
for (int i = 0; i < user.length(); i++) {
for (int i = 0, length = user.length(); i < length; i++) {
char c = user.charAt(i);
buff[n++] = (byte) (c >> 8);
buff[n++] = (byte) c;
......
......@@ -517,8 +517,9 @@ public class PageLog {
}
Data buffer = getBuffer();
buffer.writeByte((byte) FREE_LOG);
buffer.writeVarInt(pages.size());
for (int i = 0; i < pages.size(); i++) {
int size = pages.size();
buffer.writeVarInt(size);
for (int i = 0; i < size; i++) {
buffer.writeVarInt(pages.get(i));
}
write(buffer);
......
......@@ -111,7 +111,7 @@ public class RegularTable extends TableBase {
row.setSessionId(session.getId());
}
try {
for (; i < indexes.size(); i++) {
for (int size = indexes.size(); i < size; i++) {
Index index = indexes.get(i);
index.add(session, row);
checkRowCount(session, index, 1);
......
......@@ -565,12 +565,14 @@ public abstract class Table extends SchemaObjectBase {
item.setIndex(getScanIndex(session));
item.cost = item.getIndex().getCost(session, null);
ArrayList<Index> indexes = getIndexes();
for (int i = 1; indexes != null && masks != null && i < indexes.size(); i++) {
Index index = indexes.get(i);
double cost = index.getCost(session, masks);
if (cost < item.cost) {
item.cost = cost;
item.setIndex(index);
if (indexes != null && masks != null) {
for (int i = 1, size = indexes.size(); i < size; i++) {
Index index = indexes.get(i);
double cost = index.getCost(session, masks);
if (cost < item.cost) {
item.cost = cost;
item.setIndex(index);
}
}
}
return item;
......@@ -583,10 +585,12 @@ public abstract class Table extends SchemaObjectBase {
*/
public Index findPrimaryKey() {
ArrayList<Index> indexes = getIndexes();
for (int i = 0; indexes != null && i < indexes.size(); i++) {
Index idx = indexes.get(i);
if (idx.getIndexType().isPrimaryKey()) {
return idx;
if (indexes != null) {
for (int i = 0, size = indexes.size(); i < size; i++) {
Index idx = indexes.get(i);
if (idx.getIndexType().isPrimaryKey()) {
return idx;
}
}
}
return null;
......@@ -797,7 +801,7 @@ public abstract class Table extends SchemaObjectBase {
private void fireConstraints(Session session, Row oldRow, Row newRow, boolean before) {
if (constraints != null) {
// don't use enhanced for loop to avoid creating objects
for (int i = 0; i < constraints.size(); i++) {
for (int i = 0, size = constraints.size(); i < size; i++) {
Constraint constraint = constraints.get(i);
if (constraint.isBefore() == before) {
constraint.checkRow(session, this, oldRow, newRow);
......@@ -856,9 +860,10 @@ public abstract class Table extends SchemaObjectBase {
public void setCheckForeignKeyConstraints(Session session, boolean enabled, boolean checkExisting)
{
if (enabled && checkExisting) {
for (int i = 0; constraints != null && i < constraints.size(); i++) {
Constraint c = constraints.get(i);
c.checkExistingData(session);
if (constraints != null) {
for (Constraint c : constraints) {
c.checkExistingData(session);
}
}
}
checkForeignKeyConstraints = enabled;
......@@ -878,12 +883,14 @@ public abstract class Table extends SchemaObjectBase {
*/
public Index getIndexForColumn(Column column, boolean first) {
ArrayList<Index> indexes = getIndexes();
for (int i = 1; indexes != null && i < indexes.size(); i++) {
Index index = indexes.get(i);
if (index.canGetFirstOrLast()) {
int idx = index.getColumnIndex(column);
if (idx == 0) {
return index;
if (indexes != null) {
for (int i = 1, size = indexes.size(); i < size; i++) {
Index index = indexes.get(i);
if (index.canGetFirstOrLast()) {
int idx = index.getColumnIndex(column);
if (idx == 0) {
return index;
}
}
}
}
......@@ -915,12 +922,13 @@ public abstract class Table extends SchemaObjectBase {
*/
public void removeIndexOrTransferOwnership(Session session, Index index) {
boolean stillNeeded = false;
for (int i = 0; constraints != null && i < constraints.size(); i++) {
Constraint cons = constraints.get(i);
if (cons.usesIndex(index)) {
cons.setIndexOwner(index);
database.update(session, cons);
stillNeeded = true;
if (constraints != null) {
for (Constraint cons : constraints) {
if (cons.usesIndex(index)) {
cons.setIndexOwner(index);
database.update(session, cons);
stillNeeded = true;
}
}
}
if (!stillNeeded) {
......
......@@ -289,8 +289,9 @@ public class Csv implements SimpleRowSource {
return data;
}
}
StringBuilder buff = new StringBuilder(data.length());
for (int i = 0; i < data.length(); i++) {
int length = data.length();
StringBuilder buff = new StringBuilder(length);
for (int i = 0; i < length; i++) {
char ch = data.charAt(i);
if (ch == fieldDelimiter || ch == escapeCharacter) {
buff.append(escapeCharacter);
......@@ -357,7 +358,7 @@ public class Csv implements SimpleRowSource {
}
private boolean isSimpleColumnName(String columnName) {
for (int i = 0; i < columnName.length(); i++) {
for (int i = 0, length = columnName.length(); i < length; i++) {
char ch = columnName.charAt(i);
if (i == 0) {
if (ch != '_' && !Character.isLetter(ch)) {
......
......@@ -173,18 +173,19 @@ public class CacheLRU implements Cache {
}
Collections.sort(changed);
int max = maxMemory;
int size = changed.size();
try {
// temporary disable size checking,
// to avoid stack overflow
maxMemory = Integer.MAX_VALUE;
for (i = 0; i < changed.size(); i++) {
for (i = 0; i < size; i++) {
CacheObject rec = changed.get(i);
writer.writeBack(rec);
}
} finally {
maxMemory = max;
}
for (i = 0; i < changed.size(); i++) {
for (i = 0; i < size; i++) {
CacheObject rec = changed.get(i);
remove(rec.getPos());
if (SysProperties.CHECK) {
......
......@@ -108,9 +108,10 @@ public class StringUtils {
if (s == null) {
return "NULL";
}
StringBuilder buff = new StringBuilder(s.length() + 2);
int length = s.length();
StringBuilder buff = new StringBuilder(length + 2);
buff.append('\'');
for (int i = 0; i < s.length(); i++) {
for (int i = 0; i < length; i++) {
char c = s.charAt(i);
if (c == '\'') {
buff.append(c);
......@@ -134,8 +135,9 @@ public class StringUtils {
* @return the Java representation
*/
public static String javaEncode(String s) {
StringBuilder buff = new StringBuilder(s.length());
for (int i = 0; i < s.length(); i++) {
int length = s.length();
StringBuilder buff = new StringBuilder(length);
for (int i = 0; i < length; i++) {
char c = s.charAt(i);
switch (c) {
// case '\b':
......@@ -213,8 +215,9 @@ public class StringUtils {
* @return the string
*/
public static String javaDecode(String s) {
StringBuilder buff = new StringBuilder(s.length());
for (int i = 0; i < s.length(); i++) {
int length = s.length();
StringBuilder buff = new StringBuilder(length);
for (int i = 0; i < length; i++) {
char c = s.charAt(i);
if (c == '"') {
break;
......@@ -449,9 +452,10 @@ public class StringUtils {
* @return the decoded string
*/
public static String urlDecode(String encoded) {
byte[] buff = new byte[encoded.length()];
int length = encoded.length();
byte[] buff = new byte[length];
int j = 0;
for (int i = 0; i < encoded.length(); i++) {
for (int i = 0; i < length; i++) {
char ch = encoded.charAt(i);
if (ch == '+') {
buff[j++] = ' ';
......@@ -485,18 +489,19 @@ public class StringUtils {
if (s == null) {
return null;
}
if (s.length() == 0) {
int length = s.length();
if (length == 0) {
return new String[0];
}
ArrayList<String> list = New.arrayList();
StringBuilder buff = new StringBuilder(s.length());
for (int i = 0; i < s.length(); i++) {
StringBuilder buff = new StringBuilder(length);
for (int i = 0; i < length; i++) {
char c = s.charAt(i);
if (c == separatorChar) {
String e = buff.toString();
list.add(trim ? e.trim() : e);
buff.setLength(0);
} else if (c == '\\' && i < s.length() - 1) {
} else if (c == '\\' && i < length - 1) {
buff.append(s.charAt(++i));
} else {
buff.append(c);
......@@ -525,7 +530,7 @@ public class StringUtils {
if (s == null) {
s = "";
}
for (int j = 0; j < s.length(); j++) {
for (int j = 0, length = s.length(); j < length; j++) {
char c = s.charAt(j);
if (c == '\\' || c == separatorChar) {
buff.append('\\');
......@@ -656,8 +661,9 @@ public class StringUtils {
* @return the escaped text
*/
public static String xmlText(String text) {
StringBuilder buff = new StringBuilder(text.length());
for (int i = 0; i < text.length(); i++) {
int length = text.length();
StringBuilder buff = new StringBuilder(length);
for (int i = 0; i < length; i++) {
char ch = text.charAt(i);
switch (ch) {
case '<':
......@@ -745,9 +751,10 @@ public class StringUtils {
* @return the double quoted text
*/
public static String quoteIdentifier(String s) {
StringBuilder buff = new StringBuilder(s.length() + 2);
int length = s.length();
StringBuilder buff = new StringBuilder(length + 2);
buff.append('\"');
for (int i = 0; i < s.length(); i++) {
for (int i = 0; i < length; i++) {
char c = s.charAt(i);
if (c == '"') {
buff.append(c);
......
......@@ -351,7 +351,7 @@ public class DataType {
new String[]{"RESULT_SET"},
400
);
for (int i = 0; i < TYPES_BY_VALUE_TYPE.size(); i++) {
for (int i = 0, size = TYPES_BY_VALUE_TYPE.size(); i < size; i++) {
DataType dt = TYPES_BY_VALUE_TYPE.get(i);
if (dt == null) {
DbException.throwInternalError("unmapped type " + i);
......
......@@ -90,7 +90,7 @@ public class ValueUuid extends Value {
*/
public static ValueUuid get(String s) {
long low = 0, high = 0;
for (int i = 0, j = 0; i < s.length(); i++) {
for (int i = 0, j = 0, length = s.length(); i < length; i++) {
char c = s.charAt(i);
if (c >= '0' && c <= '9') {
low = (low << 4) | (c - '0');
......
......@@ -43,11 +43,11 @@ public class TestRunscript extends TestBase implements Trigger {
Connection conn;
conn = getConnection("runscript");
final Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key) as select x from system_range(1, 10000)");
stat.execute("create table test(id int primary key) as select x from system_range(1, 20000)");
stat.execute("script simple drop to '"+getBaseDir()+"/backup.sql'");
stat.execute("set throttle 1000");
// need to wait a bit (throttle is only used every 50 ms)
Thread.sleep(100);
Thread.sleep(200);
final String dir = getBaseDir();
final SQLException[] ex = new SQLException[1];
Thread thread;
......@@ -62,7 +62,7 @@ public class TestRunscript extends TestBase implements Trigger {
}
};
thread.start();
Thread.sleep(100);
Thread.sleep(200);
stat.cancel();
thread.join();
e = ex[0];
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论