提交 40d18c4a 编写于 作者: H Hongze Cheng

more TDB

上级 3c044ef2
...@@ -95,6 +95,7 @@ int tdbPageDropCell(SPage *pPage, int idx) { ...@@ -95,6 +95,7 @@ int tdbPageDropCell(SPage *pPage, int idx) {
static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell) { static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell) {
SCell *pCell; SCell *pCell;
SFreeCell *pFreeCell; SFreeCell *pFreeCell;
u8 *pOffset;
int ret; int ret;
ASSERT(pPage->nFree > size + pPage->szOffset); ASSERT(pPage->nFree > size + pPage->szOffset);
...@@ -106,22 +107,32 @@ static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell) { ...@@ -106,22 +107,32 @@ static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell) {
if (pPage->pFreeEnd - pPage->pFreeStart > size + pPage->szOffset) { if (pPage->pFreeEnd - pPage->pFreeStart > size + pPage->szOffset) {
pPage->pFreeEnd -= size; pPage->pFreeEnd -= size;
pPage->pFreeStart += pPage->szOffset; pPage->pFreeStart += pPage->szOffset;
pCell = pPage->pFreeEnd; pCell = pPage->pFreeEnd;
} }
// 2. Try to allocate from the page free list // 2. Try to allocate from the page free list
if (pCell == NULL && TDB_PAGE_FCELL(pPage)) { if ((pCell == NULL) && (pPage->pFreeEnd - pPage->pFreeStart >= pPage->szOffset) && TDB_PAGE_FCELL(pPage)) {
pCell = pPage->pData + TDB_PAGE_FCELL(pPage); pCell = pPage->pData + TDB_PAGE_FCELL(pPage);
// TODO: pOffset = TDB_PAGE_FCELL(pPage);
for (;;) { for (;;) {
pFreeCell = (SFreeCell *)pCell; pFreeCell = (SFreeCell *)pCell;
if (pFreeCell->size >= size) { if (pFreeCell->size >= size) {
if (pFreeCell->size - size >= 4 /*TODO*/) {
((SFreeCell *)(pCell + size))[0].size = pFreeCell->size - size;
((SFreeCell *)(pCell + size))[0].nOffset = pFreeCell->nOffset;
// *(u16 *)pOffset = pCell + size - pPage->pData;
} else {
TDB_PAGE_NFREE_SET(pPage, TDB_PAGE_NFREE(pPage) + pFreeCell->size - size);
// *(u16 *)pOffset = pFreeCell->nOffset;
}
break; break;
} }
if (pFreeCell->nOffset) { if (pFreeCell->nOffset) {
pCell = pPage->pData + pFreeCell->nOffset; pCell = pPage->pData + pFreeCell->nOffset;
// TODO: pOffset = &(pFreeCell->nOffset);
} else { } else {
pCell = NULL; pCell = NULL;
break; break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册