code optimization
This commit is contained in:
parent
c1370a940e
commit
07227d7ad2
|
@ -1924,27 +1924,21 @@ typedef struct {
|
|||
STSma* tSma;
|
||||
} STSmaWrapper;
|
||||
|
||||
static FORCE_INLINE void tdDestroyTSma(STSma* pSma, bool releaseSelf) {
|
||||
static FORCE_INLINE void tdDestroyTSma(STSma* pSma) {
|
||||
if (pSma) {
|
||||
tfree(pSma->colIds);
|
||||
tfree(pSma->funcIds);
|
||||
if (releaseSelf) {
|
||||
free(pSma);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tdDestroyTSmaWrapper(STSmaWrapper* pSW, bool releaseSelf) {
|
||||
static FORCE_INLINE void tdDestroyTSmaWrapper(STSmaWrapper* pSW) {
|
||||
if (pSW) {
|
||||
if (pSW->tSma) {
|
||||
for (uint32_t i = 0; i < pSW->number; ++i) {
|
||||
tdDestroyTSma(pSW->tSma + i, false);
|
||||
tdDestroyTSma(pSW->tSma + i);
|
||||
}
|
||||
tfree(pSW->tSma);
|
||||
}
|
||||
if (releaseSelf) {
|
||||
free(pSW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2031,7 +2025,7 @@ static FORCE_INLINE void* tDecodeTSmaWrapper(void* buf, STSmaWrapper* pSW) {
|
|||
for (uint32_t i = 0; i < pSW->number; ++i) {
|
||||
if ((buf = tDecodeTSma(buf, pSW->tSma + i)) == NULL) {
|
||||
for (uint32_t j = i; j >= 0; --i) {
|
||||
tdDestroyTSma(pSW->tSma + j, false);
|
||||
tdDestroyTSma(pSW->tSma + j);
|
||||
}
|
||||
free(pSW->tSma);
|
||||
return NULL;
|
||||
|
|
|
@ -896,14 +896,16 @@ STSmaWrapper *metaGetSmaInfoByUid(SMeta *pMeta, tb_uid_t uid) {
|
|||
STSma *tptr = (STSma *)realloc(pSW->tSma, pSW->number * sizeof(STSma));
|
||||
if (tptr == NULL) {
|
||||
metaCloseSmaCurosr(pCur);
|
||||
tdDestroyTSmaWrapper(pSW, true);
|
||||
tdDestroyTSmaWrapper(pSW);
|
||||
tfree(pSW);
|
||||
return NULL;
|
||||
}
|
||||
pSW->tSma = tptr;
|
||||
pBuf = pval.data;
|
||||
if (tDecodeTSma(pBuf, pSW->tSma + pSW->number - 1) == NULL) {
|
||||
metaCloseSmaCurosr(pCur);
|
||||
tdDestroyTSmaWrapper(pSW, true);
|
||||
tdDestroyTSmaWrapper(pSW);
|
||||
tfree(pSW);
|
||||
return NULL;
|
||||
}
|
||||
continue;
|
||||
|
|
|
@ -94,8 +94,8 @@ TEST(testCase, tSmaEncodeDecodeTest) {
|
|||
}
|
||||
|
||||
// resource release
|
||||
tdDestroyTSma(&tSma, false);
|
||||
tdDestroyTSmaWrapper(&dstTSmaWrapper, false);
|
||||
tdDestroyTSma(&tSma);
|
||||
tdDestroyTSmaWrapper(&dstTSmaWrapper);
|
||||
}
|
||||
|
||||
TEST(testCase, tSma_DB_Put_Get_Del_Test) {
|
||||
|
@ -152,14 +152,16 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
|
|||
printf("name1 = %s\n", qSmaCfg->indexName);
|
||||
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1);
|
||||
EXPECT_EQ(qSmaCfg->tableUid, tSma.tableUid);
|
||||
tdDestroyTSma(qSmaCfg, true);
|
||||
tdDestroyTSma(qSmaCfg);
|
||||
free(qSmaCfg);
|
||||
|
||||
qSmaCfg = metaGetSmaInfoByName(pMeta, smaIndexName2);
|
||||
assert(qSmaCfg != NULL);
|
||||
printf("name2 = %s\n", qSmaCfg->indexName);
|
||||
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2);
|
||||
EXPECT_EQ(qSmaCfg->interval, tSma.interval);
|
||||
tdDestroyTSma(qSmaCfg, true);
|
||||
tdDestroyTSma(qSmaCfg);
|
||||
free(qSmaCfg);
|
||||
|
||||
// get index name by table uid
|
||||
SMSmaCursor *pSmaCur = metaOpenSmaCursor(pMeta, tbUid);
|
||||
|
@ -189,7 +191,7 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
|
|||
metaRemoveSmaFromDb(pMeta, smaIndexName1);
|
||||
metaRemoveSmaFromDb(pMeta, smaIndexName2);
|
||||
|
||||
tdDestroyTSma(&tSma, false);
|
||||
tdDestroyTSma(&tSma);
|
||||
metaClose(pMeta);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue