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

Do not pass HashMap to SequenceMap.init()

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