This commit is contained in:
Hongze Cheng 2022-03-20 12:02:26 +00:00
parent 57a92869ae
commit 0353e59081
1 changed files with 32 additions and 2 deletions

View File

@ -220,8 +220,38 @@ _alloc_finish:
return 0; return 0;
} }
static int tdbPageFree(SPage *pPage, int idx, SCell *pCell, int size) { static int tdbPageFree(SPage *pPage, int idx, SCell *pCell, int szCell) {
// TODO int nFree;
int cellFree;
u8 *dest;
u8 *src;
ASSERT(pCell >= pPage->pFreeEnd);
ASSERT(pCell + szCell <= (u8 *)(pPage->pPageFtr));
ASSERT(pCell == TDB_PAGE_CELL_AT(pPage, idx));
nFree = TDB_PAGE_NFREE(pPage);
if (pCell == pPage->pFreeEnd) {
pPage->pFreeEnd += szCell;
TDB_PAGE_CCELLS_SET(pPage, pPage->pFreeEnd - pPage->pData);
} else {
if (szCell >= TDB_PAGE_FREE_CELL_SIZE(pPage)) {
cellFree = TDB_PAGE_FCELL(pPage);
pPage->pPageMethods->setFreeCellInfo(pCell, szCell, cellFree);
TDB_PAGE_FCELL_SET(pPage, pCell - pPage->pData);
} else {
ASSERT(0);
}
}
dest = pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * idx;
src = dest + TDB_PAGE_OFFSET_SIZE(pPage);
memmove(dest, src, pPage->pFreeStart - src);
pPage->pFreeStart -= TDB_PAGE_OFFSET_SIZE(pPage);
nFree = nFree + szCell + TDB_PAGE_OFFSET_SIZE(pPage);
TDB_PAGE_NFREE_SET(pPage, nFree);
return 0; return 0;
} }