提交 764b090e authored 作者: Andrei Tokar's avatar Andrei Tokar

one more little de-duping

上级 8ca496eb
...@@ -1479,11 +1479,7 @@ public class MVStore { ...@@ -1479,11 +1479,7 @@ public class MVStore {
childCollector.visit(page.getChildPagePos(i), executorService, executingThreadCounter); childCollector.visit(page.getChildPagePos(i), executorService, executingThreadCounter);
} }
} }
// and cache resulting set of chunk ids cacheCollectedChunkIds(pos, childCollector);
if (childCollector != this) {
int[] chunkIds = childCollector.getChunkIds();
cacheChunkRef.put(pos, chunkIds, Constants.MEMORY_ARRAY + 4 * chunkIds.length);
}
} }
public void visit(long pos, ThreadPoolExecutor executorService, AtomicInteger executingThreadCounter) { public void visit(long pos, ThreadPoolExecutor executorService, AtomicInteger executingThreadCounter) {
...@@ -1501,7 +1497,7 @@ public class MVStore { ...@@ -1501,7 +1497,7 @@ public class MVStore {
registerChunk(chunkId); registerChunk(chunkId);
} }
} else { } else {
final ChunkIdsCollector childCollector = new ChunkIdsCollector(this); ChunkIdsCollector childCollector = cacheChunkRef != null ? new ChunkIdsCollector(this) : this;
Page page; Page page;
if (cache != null && (page = cache.get(pos)) != null) { if (cache != null && (page = cache.get(pos)) != null) {
// there is a full page in cache, use it // there is a full page in cache, use it
...@@ -1511,11 +1507,7 @@ public class MVStore { ...@@ -1511,11 +1507,7 @@ public class MVStore {
ByteBuffer buff = readBufferForPage(pos, getMapId()); ByteBuffer buff = readBufferForPage(pos, getMapId());
Page.readChildrenPositions(buff, pos, childCollector, executorService, executingThreadCounter); Page.readChildrenPositions(buff, pos, childCollector, executorService, executingThreadCounter);
} }
// and cache resulting set of chunk ids cacheCollectedChunkIds(pos, childCollector);
if (cacheChunkRef != null) {
chunkIds = childCollector.getChunkIds();
cacheChunkRef.put(pos, chunkIds, Constants.MEMORY_ARRAY + 4 * chunkIds.length);
}
} }
} }
...@@ -1525,13 +1517,15 @@ public class MVStore { ...@@ -1525,13 +1517,15 @@ public class MVStore {
} }
} }
private int[] getChunkIds() { private void cacheCollectedChunkIds(long pos, ChunkIdsCollector childCollector) {
int[] chunkIds = new int[referencedChunks.size()]; if (childCollector != this) {
int[] chunkIds = new int[childCollector.referencedChunks.size()];
int index = 0; int index = 0;
for (Integer chunkId : referencedChunks.keySet()) { for (Integer chunkId : childCollector.referencedChunks.keySet()) {
chunkIds[index++] = chunkId; chunkIds[index++] = chunkId;
} }
return chunkIds; cacheChunkRef.put(pos, chunkIds, Constants.MEMORY_ARRAY + 4 * chunkIds.length);
}
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论