提交 dbfd53ce authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Do not copy result of DataUtils.parseMap() to a new maps

上级 ca720764
...@@ -445,6 +445,7 @@ public final class MVStore { ...@@ -445,6 +445,7 @@ 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();
...@@ -455,15 +456,14 @@ public final class MVStore { ...@@ -455,15 +456,14 @@ public final class MVStore {
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));
c = New.hashMap(); // Cast from HashMap<String, String> to HashMap<String, Object> is safe
c.putAll(DataUtils.parseMap(config)); c = (HashMap) DataUtils.parseMap(config);
c.put("id", id); c.put("id", id);
map.init(this, c); map.init(this, c);
root = getRootPos(meta, id); root = getRootPos(meta, id);
...@@ -2725,7 +2725,18 @@ public final class MVStore { ...@@ -2725,7 +2725,18 @@ public final class MVStore {
*/ */
public static class Builder { public static class Builder {
private final HashMap<String, Object> config = New.hashMap(); private final HashMap<String, Object> config;
private Builder(HashMap<String, Object> config) {
this.config = config;
}
/**
* Creates new instance of MVStore.Builder.
*/
public Builder() {
config = New.hashMap();
}
private Builder set(String key, Object value) { private Builder set(String key, Object value) {
config.put(key, value); config.put(key, value);
...@@ -2938,11 +2949,10 @@ public final class MVStore { ...@@ -2938,11 +2949,10 @@ public final class MVStore {
* @param s the string representation * @param s the string representation
* @return the builder * @return the builder
*/ */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Builder fromString(String s) { public static Builder fromString(String s) {
HashMap<String, String> config = DataUtils.parseMap(s); // Cast from HashMap<String, String> to HashMap<String, Object> is safe
Builder builder = new Builder(); return new Builder((HashMap) DataUtils.parseMap(s));
builder.config.putAll(config);
return builder;
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论