refact more
This commit is contained in:
parent
0a62868d5e
commit
f75f60c84c
|
@ -213,11 +213,16 @@ int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, in
|
||||||
}
|
}
|
||||||
|
|
||||||
int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen) {
|
int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen) {
|
||||||
|
return tdbBtreePGet(pBt, pKey, kLen, NULL, NULL, ppVal, vLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen) {
|
||||||
SBTC btc;
|
SBTC btc;
|
||||||
SCell *pCell;
|
SCell *pCell;
|
||||||
int cret;
|
int cret;
|
||||||
int ret;
|
int ret;
|
||||||
void *pVal;
|
void *pTKey = NULL;
|
||||||
|
void *pTVal = NULL;
|
||||||
SCellDecoder cd;
|
SCellDecoder cd;
|
||||||
|
|
||||||
tdbBtcOpen(&btc, pBt);
|
tdbBtcOpen(&btc, pBt);
|
||||||
|
@ -226,7 +231,6 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
tdbBtcClose(&btc);
|
tdbBtcClose(&btc);
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cret) {
|
if (cret) {
|
||||||
|
@ -237,55 +241,30 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen
|
||||||
pCell = tdbPageGetCell(btc.pPage, btc.idx);
|
pCell = tdbPageGetCell(btc.pPage, btc.idx);
|
||||||
tdbBtreeDecodeCell(btc.pPage, pCell, &cd);
|
tdbBtreeDecodeCell(btc.pPage, pCell, &cd);
|
||||||
|
|
||||||
*vLen = cd.vLen;
|
if (ppKey) {
|
||||||
pVal = TDB_REALLOC(*ppVal, *vLen);
|
|
||||||
if (pVal == NULL) {
|
|
||||||
tdbBtcClose(&btc);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
*ppVal = pVal;
|
|
||||||
memcpy(*ppVal, cd.pVal, cd.vLen);
|
|
||||||
|
|
||||||
tdbBtcClose(&btc);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen) {
|
|
||||||
SBTC btc;
|
|
||||||
SCell *pCell;
|
|
||||||
int cret;
|
|
||||||
void *pTKey;
|
|
||||||
void *pTVal;
|
|
||||||
SCellDecoder cd;
|
|
||||||
|
|
||||||
tdbBtcOpen(&btc, pBt);
|
|
||||||
|
|
||||||
tdbBtcMoveTo(&btc, pKey, kLen, &cret);
|
|
||||||
if (cret) {
|
|
||||||
return cret;
|
|
||||||
}
|
|
||||||
|
|
||||||
pCell = tdbPageGetCell(btc.pPage, btc.idx);
|
|
||||||
tdbBtreeDecodeCell(btc.pPage, pCell, &cd);
|
|
||||||
|
|
||||||
pTKey = TDB_REALLOC(*ppKey, cd.kLen);
|
pTKey = TDB_REALLOC(*ppKey, cd.kLen);
|
||||||
pTVal = TDB_REALLOC(*ppVal, cd.vLen);
|
if (pTKey == NULL) {
|
||||||
|
tdbBtcClose(&btc);
|
||||||
if (pTKey == NULL || pTVal == NULL) {
|
ASSERT(0);
|
||||||
TDB_FREE(pTKey);
|
return -1;
|
||||||
TDB_FREE(pTVal);
|
}
|
||||||
|
*ppKey = pTKey;
|
||||||
|
*pkLen = cd.kLen;
|
||||||
|
memcpy(*ppKey, cd.pKey, cd.kLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppKey = pTKey;
|
pTVal = TDB_REALLOC(*ppVal, cd.vLen);
|
||||||
|
if (pTVal == NULL) {
|
||||||
|
tdbBtcClose(&btc);
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
*ppVal = pTVal;
|
*ppVal = pTVal;
|
||||||
*pkLen = cd.kLen;
|
|
||||||
*vLen = cd.vLen;
|
*vLen = cd.vLen;
|
||||||
|
|
||||||
memcpy(*ppKey, cd.pKey, cd.kLen);
|
|
||||||
memcpy(*ppVal, cd.pVal, cd.vLen);
|
memcpy(*ppVal, cd.pVal, cd.vLen);
|
||||||
|
|
||||||
|
tdbBtcClose(&btc);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue