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