This commit is contained in:
Hongze Cheng 2022-03-15 09:52:31 +00:00
parent 0e30b7604c
commit 28d3a1dbe8
1 changed files with 16 additions and 0 deletions

View File

@ -36,6 +36,7 @@ struct SBTree {
int minLocal; int minLocal;
int maxLeaf; int maxLeaf;
int minLeaf; int minLeaf;
u8 *pTmp;
}; };
typedef struct __attribute__((__packed__)) { typedef struct __attribute__((__packed__)) {
@ -125,6 +126,7 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p
SCell *pCell; SCell *pCell;
int szCell; int szCell;
int cret; int cret;
SBTree *pBt;
ret = tdbBtCursorMoveTo(pCur, pKey, kLen, &cret); ret = tdbBtCursorMoveTo(pCur, pKey, kLen, &cret);
if (ret < 0) { if (ret < 0) {
@ -146,6 +148,17 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p
} }
} }
// TODO: refact code here
pBt = pCur->pBt;
if (!pBt->pTmp) {
pBt->pTmp = (u8 *)malloc(pBt->pageSize);
if (pBt->pTmp == NULL) {
return -1;
}
}
pCell = pBt->pTmp;
// Encode the cell // Encode the cell
ret = tdbBtreeEncodeCell(pCur->pPage, pKey, kLen, pVal, vLen, pCell, &szCell); ret = tdbBtreeEncodeCell(pCur->pPage, pKey, kLen, pVal, vLen, pCell, &szCell);
if (ret < 0) { if (ret < 0) {
@ -349,6 +362,9 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) {
pPage->minLocal = pBt->minLocal; pPage->minLocal = pBt->minLocal;
} }
// TODO: need to update the SPage.nFree
pPage->nFree = pPage->pFreeEnd - pPage->pFreeStart;
return 0; return 0;
} }