提交 8fc4d179 authored 作者: Andrei Tokar's avatar Andrei Tokar

addressing code review comments

上级 15b5949c
...@@ -1317,7 +1317,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1317,7 +1317,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
return rootReference; return rootReference;
} }
private Page replacePage(CursorPos path, Page replacement, IntValueHolder unsavedMemoryHolder) { private static Page replacePage(CursorPos path, Page replacement, IntValueHolder unsavedMemoryHolder) {
int unsavedMemory = replacement.getMemory(); int unsavedMemory = replacement.getMemory();
while (path != null) { while (path != null) {
Page child = replacement; Page child = replacement;
...@@ -1363,17 +1363,17 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1363,17 +1363,17 @@ public class MVMap<K, V> extends AbstractMap<K, V>
public void trimLast() { public void trimLast() {
RootReference rootReference = getRoot(); RootReference rootReference = getRoot();
int appendCounter = rootReference.getAppendCounter(); int appendCounter = rootReference.getAppendCounter();
boolean fallback = appendCounter == 0; boolean useRegularRemove = appendCounter == 0;
if (!fallback) { if (!useRegularRemove) {
rootReference = lockRoot(rootReference, 1); rootReference = lockRoot(rootReference, 1);
appendCounter = rootReference.getAppendCounter(); appendCounter = rootReference.getAppendCounter();
fallback = appendCounter == 0; useRegularRemove = appendCounter == 0;
if (!fallback) { if (!useRegularRemove) {
--appendCounter; --appendCounter;
} }
unlockRoot(rootReference.root, appendCounter); unlockRoot(rootReference.root, appendCounter);
} }
if (fallback) { if (useRegularRemove) {
Page lastLeaf = rootReference.root.getAppendCursorPos(null).page; Page lastLeaf = rootReference.root.getAppendCursorPos(null).page;
assert lastLeaf.isLeaf(); assert lastLeaf.isLeaf();
assert lastLeaf.getKeyCount() > 0; assert lastLeaf.getKeyCount() > 0;
...@@ -1751,6 +1751,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1751,6 +1751,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
public void reset() {} public void reset() {}
} }
@SuppressWarnings("unchecked")
public V operate(K key, V value, DecisionMaker<? super V> decisionMaker) { public V operate(K key, V value, DecisionMaker<? super V> decisionMaker) {
beforeWrite(); beforeWrite();
IntValueHolder unsavedMemoryHolder = new IntValueHolder(); IntValueHolder unsavedMemoryHolder = new IntValueHolder();
...@@ -1773,7 +1774,6 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1773,7 +1774,6 @@ public class MVMap<K, V> extends AbstractMap<K, V>
int index = pos.index; int index = pos.index;
tip = pos; tip = pos;
pos = pos.parent; pos = pos.parent;
//noinspection unchecked
result = index < 0 ? null : (V)p.getValue(index); result = index < 0 ? null : (V)p.getValue(index);
Decision decision = decisionMaker.decide(result, value); Decision decision = decisionMaker.decide(result, value);
...@@ -1990,5 +1990,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -1990,5 +1990,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
private static final class IntValueHolder { private static final class IntValueHolder {
int value; int value;
IntValueHolder() {}
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论