提交 bc08e313 authored 作者: Noel Grandin's avatar Noel Grandin

add entries iterator to ValueHashMap

speeds up this query by about 30%
上级 e241c7b6
...@@ -28,6 +28,7 @@ import java.util.ArrayList; ...@@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
/** /**
* This class represents a simple SELECT statement. * This class represents a simple SELECT statement.
...@@ -420,10 +421,9 @@ public class Select extends Query { ...@@ -420,10 +421,9 @@ public class Select extends Query {
groupByData.put(defaultGroup, groupByData.put(defaultGroup,
new Object[Math.max(exprToIndexInGroupByData.size(), expressions.size())]); new Object[Math.max(exprToIndexInGroupByData.size(), expressions.size())]);
} }
ArrayList<Value> keys = groupByData.keys(); for (Map.Entry<Value, Object[]> entry : groupByData.entries()) {
for (Value v : keys) { currentGroupsKey = (ValueArray) entry.getKey();
currentGroupsKey = (ValueArray) v; currentGroupByExprData = entry.getValue();
currentGroupByExprData = groupByData.get(currentGroupsKey);
Value[] keyValues = currentGroupsKey.getList(); Value[] keyValues = currentGroupsKey.getList();
Value[] row = new Value[columnCount]; Value[] row = new Value[columnCount];
for (int j = 0; groupIndex != null && j < groupIndex.length; j++) { for (int j = 0; groupIndex != null && j < groupIndex.length; j++) {
......
...@@ -6,7 +6,10 @@ ...@@ -6,7 +6,10 @@
package org.h2.util; package org.h2.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.mvstore.DataUtils;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
...@@ -188,6 +191,39 @@ public class ValueHashMap<V> extends HashBase { ...@@ -188,6 +191,39 @@ public class ValueHashMap<V> extends HashBase {
} }
return list; return list;
} }
public Iterable<Map.Entry<Value, V>> entries() {
return new EntryIterable();
}
private final class EntryIterable implements Iterable<Map.Entry<Value, V>> {
@Override
public Iterator<Map.Entry<Value, V>> iterator() {
return new EntryIterator();
}
}
private final class EntryIterator implements Iterator<Map.Entry<Value, V>> {
int keysIndex = -1;
@Override
public boolean hasNext() {
if (keysIndex >= keys.length)
return false;
do {
keysIndex++;
if (keysIndex >= keys.length)
return false;
if (keys[keysIndex] != null && keys[keysIndex] != ValueNull.DELETED)
return true;
} while (true);
}
@Override
public Map.Entry<Value, V> next() {
return new DataUtils.MapEntry<Value, V>(keys[keysIndex], values[keysIndex]);
}
}
/** /**
* Get the list of values. * Get the list of values.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论