From 687c268101424c003ac331fbda4600a444c816fc Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Thu, 9 Dec 2021 18:25:29 +0800 Subject: [PATCH] code optimization --- src/client/inc/tsclient.h | 7 ++++--- src/client/src/tscParseInsert.c | 14 +++++--------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index de439e6403..b63646ce64 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -529,14 +529,15 @@ static FORCE_INLINE int32_t getExtendedRowSize(STableDataBlocks *pBlock) { return pBlock->rowSize + TD_MEM_ROW_DATA_HEAD_SIZE + pBlock->boundColumnInfo.extendedVarLen; } -static FORCE_INLINE void checkAndConvertMemRow(SMemRow row, int32_t dataLen, int32_t kvLen) { +static FORCE_INLINE bool checkAndConvertMemRow(SMemRow row, int32_t dataLen, int32_t kvLen) { if (isDataRow(row)) { if (kvLen < (dataLen * KVRatioConvert)) { - memRowSetConvert(row); + return true; } } else if (kvLen > dataLen) { - memRowSetConvert(row); + return true; } + return false; } static FORCE_INLINE void initSMemRow(SMemRow row, uint8_t memRowType, STableDataBlocks *pBlock, int16_t nBoundCols) { diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 53c43f1892..0c0738677d 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -553,12 +553,13 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, b if (!isParseBindParam) { // 2. check and set convert flag + bool isNeedConvertRow = false; if (pBuilder->compareStat == ROW_COMPARE_NEED) { - checkAndConvertMemRow(row, dataLen, kvLen); + isNeedConvertRow = checkAndConvertMemRow(row, dataLen, kvLen); } // 3. set the null value for the columns that do not assign values - if ((spd->numOfBound < spd->numOfCols) && isDataRow(row) && !isNeedConvertRow(row)) { + if ((spd->numOfBound < spd->numOfCols) && isDataRow(row) && !isNeedConvertRow) { SDataRow dataRow = memRowDataBody(row); for (int32_t i = 0; i < spd->numOfCols; ++i) { if (spd->cols[i].valStat == VAL_STAT_NONE) { @@ -568,14 +569,13 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, b } // 4. perform the convert - if (isNeedConvertRow(row)) { + if (isNeedConvertRow) { + // put converted row to next location to minimize the memcpy convertSMemRow(row + rowSize, row, pDataBlocks); *isConverted = true; } } - // *len = getExtendedRowSize(pDataBlocks); - return TSDB_CODE_SUCCESS; } @@ -652,8 +652,6 @@ int32_t tsParseValues(char **str, STableDataBlocks *pDataBlock, int maxRows, SIn maxRows = tSize; } - // int32_t len = 0; - code = tsParseOneRow(str, pDataBlock, precision, &isConverted, extendedRowSize, tmpTokenBuf, pInsertParam); if (code != TSDB_CODE_SUCCESS) { // error message has been set in tsParseOneRow, return directly return TSDB_CODE_TSC_SQL_SYNTAX_ERROR; @@ -1761,8 +1759,6 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int32_t numOfRow char *lineptr = line; strtolower(line, line); - // int32_t len = 0; - code = tsParseOneRow(&lineptr, pTableDataBlock, tinfo.precision, &isConverted, extendedRowSize, tokenBuf, pInsertParam); if (code != TSDB_CODE_SUCCESS || pTableDataBlock->numOfParams > 0) { -- GitLab