提交 8bef9bc8 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Do not pass HashMap to SequenceMap.init()

上级 c72a244c
......@@ -8,7 +8,6 @@ package org.h2.mvstore;
import java.util.AbstractList;
import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
......@@ -96,12 +95,13 @@ public class MVMap<K, V> extends AbstractMap<K, V>
* Open this map with the given store and configuration.
*
* @param store the store
* @param config the configuration
* @param id map id
* @param createVersion version in which this map was created
*/
protected void init(MVStore store, HashMap<String, Object> config) {
protected void init(MVStore store, int id, long createVersion) {
this.store = store;
this.id = DataUtils.readHexInt(config, "id", 0);
this.createVersion = DataUtils.readHexLong(config, "createVersion", 0);
this.id = id;
this.createVersion = createVersion;
this.writeVersion = store.getCurrentVersion();
this.root = Page.createEmpty(this, -1);
}
......@@ -1112,10 +1112,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
MVMap<K, V> openReadOnly() {
MVMap<K, V> m = new MVMap<>(keyType, valueType);
m.readOnly = true;
HashMap<String, Object> config = new HashMap<>();
config.put("id", id);
config.put("createVersion", createVersion);
m.init(store, config);
m.init(store, id, createVersion);
m.root = root;
return m;
}
......
......@@ -336,10 +336,7 @@ public final class MVStore {
(UncaughtExceptionHandler)config.get("backgroundExceptionHandler");
meta = new MVMap<>(StringDataType.INSTANCE,
StringDataType.INSTANCE);
HashMap<String, Object> c = new HashMap<>();
c.put("id", 0);
c.put("createVersion", currentVersion);
meta.init(this, c);
meta.init(this, 0, currentVersion);
if (this.fileStore != null) {
retentionTime = this.fileStore.getDefaultRetentionTime();
int kb = DataUtils.getConfigParam(config, "autoCommitBufferSize", 1024);
......@@ -445,35 +442,28 @@ public final class MVStore {
* @param builder the map builder
* @return the map
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public synchronized <M extends MVMap<K, V>, K, V> M openMap(
String name, MVMap.MapBuilder<M, K, V> builder) {
checkOpen();
String x = meta.get("name." + name);
int id;
long root;
HashMap<String, Object> c;
M map;
if (x != null) {
id = DataUtils.parseHexInt(x);
@SuppressWarnings("unchecked")
M old = (M) maps.get(id);
if (old != null) {
return old;
}
map = builder.create();
String config = meta.get(MVMap.getMapKey(id));
// Cast from HashMap<String, String> to HashMap<String, Object> is safe
c = (HashMap) DataUtils.parseMap(config);
c.put("id", id);
map.init(this, c);
map.init(this, id, DataUtils.readHexLong(DataUtils.parseMap(config), "createVersion", 0));
root = getRootPos(meta, id);
} else {
c = new HashMap<>();
id = ++lastMapId;
c.put("id", id);
c.put("createVersion", currentVersion);
map = builder.create();
map.init(this, c);
map.init(this, id, currentVersion);
markMetaChanged();
x = Integer.toHexString(id);
meta.put(MVMap.getMapKey(id), map.asString(name));
......
......@@ -6,7 +6,6 @@
package org.h2.test.store;
import java.util.AbstractSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import org.h2.mvstore.MVMap;
......@@ -32,8 +31,8 @@ public class SequenceMap extends MVMap<Long, Long> {
}
@Override
public void init(MVStore store, HashMap<String, Object> config) {
super.init(store, config);
public void init(MVStore store, int id, long createVersion) {
super.init(store, id, createVersion);
}
@Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论