From 07227d7ad20fc5c18ebb9884cb0f593a95a166d6 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Mon, 7 Mar 2022 18:27:31 +0800 Subject: [PATCH] code optimization --- include/common/tmsg.h | 14 ++++---------- source/dnode/vnode/src/meta/metaBDBImpl.c | 6 ++++-- source/dnode/vnode/test/tsdbSmaTest.cpp | 12 +++++++----- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 65860d4959..f0e1944e25 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -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; diff --git a/source/dnode/vnode/src/meta/metaBDBImpl.c b/source/dnode/vnode/src/meta/metaBDBImpl.c index 03a2937679..c2f147bcaa 100644 --- a/source/dnode/vnode/src/meta/metaBDBImpl.c +++ b/source/dnode/vnode/src/meta/metaBDBImpl.c @@ -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; diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index 97157fc49c..d97dca8469 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -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); } -- GitLab