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

Inline read() to make PageFreeList.used final again

上级 3ec08667
...@@ -23,18 +23,17 @@ public class PageFreeList extends Page { ...@@ -23,18 +23,17 @@ public class PageFreeList extends Page {
private static final int DATA_START = 3; private static final int DATA_START = 3;
private final PageStore store; private final PageStore store;
private BitSet used; private final BitSet used;
private final int pageCount; private final int pageCount;
private boolean full; private boolean full;
private Data data; private Data data;
private PageFreeList(PageStore store, int pageId) { private PageFreeList(PageStore store, int pageId, int pageCount, BitSet used) {
// kept in cache, and array list in page store // kept in cache, and array list in page store
setPos(pageId); setPos(pageId);
this.store = store; this.store = store;
pageCount = (store.getPageSize() - DATA_START) * 8; this.pageCount = pageCount;
used = new BitSet(pageCount); this.used = used;
used.set(0);
} }
/** /**
...@@ -46,9 +45,15 @@ public class PageFreeList extends Page { ...@@ -46,9 +45,15 @@ public class PageFreeList extends Page {
* @return the page * @return the page
*/ */
static PageFreeList read(PageStore store, Data data, int pageId) { static PageFreeList read(PageStore store, Data data, int pageId) {
PageFreeList p = new PageFreeList(store, pageId); data.reset();
data.readByte();
data.readShortInt();
int length = store.getPageSize() - DATA_START;
byte[] b = new byte[length];
data.read(b, 0, b.length);
PageFreeList p = new PageFreeList(store, pageId, length * 8, BitSet.valueOf(b));
p.data = data; p.data = data;
p.read(); p.full = false;
return p; return p;
} }
...@@ -60,7 +65,10 @@ public class PageFreeList extends Page { ...@@ -60,7 +65,10 @@ public class PageFreeList extends Page {
* @return the page * @return the page
*/ */
static PageFreeList create(PageStore store, int pageId) { static PageFreeList create(PageStore store, int pageId) {
return new PageFreeList(store, pageId); int pageCount = (store.getPageSize() - DATA_START) * 8;
BitSet used = new BitSet(pageCount);
used.set(0);
return new PageFreeList(store, pageId, pageCount, used);
} }
/** /**
...@@ -153,19 +161,6 @@ public class PageFreeList extends Page { ...@@ -153,19 +161,6 @@ public class PageFreeList extends Page {
store.update(this); store.update(this);
} }
/**
* Read the page from the disk.
*/
private void read() {
data.reset();
data.readByte();
data.readShortInt();
byte[] b = new byte[pageCount >>> 3];
data.read(b, 0, b.length);
used = BitSet.valueOf(b);
full = false;
}
@Override @Override
public void write() { public void write() {
data = store.createData(); data = store.createData();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论