optimize code
This commit is contained in:
parent
048f6ef5b9
commit
fad06f6144
|
@ -22,19 +22,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define TARRAY(TYPE) \
|
||||
struct { \
|
||||
int32_t tarray_size_; \
|
||||
int32_t tarray_neles_; \
|
||||
struct TYPE* td_array_data_; \
|
||||
}
|
||||
|
||||
#define TARRAY_SIZE(ARRAY) (ARRAY)->tarray_size_
|
||||
#define TARRAY_NELES(ARRAY) (ARRAY)->tarray_neles_
|
||||
#define TARRAY_ELE_AT(ARRAY, IDX) ((ARRAY)->td_array_data_ + idx)
|
||||
#endif
|
||||
|
||||
#define TARRAY_MIN_SIZE 8
|
||||
#define TARRAY_GET_ELEM(array, index) ((void*)((char*)((array)->pData) + (index) * (array)->elemSize))
|
||||
#define TARRAY_ELEM_IDX(array, ele) (POINTER_DISTANCE(ele, (array)->pData) / (array)->elemSize)
|
||||
|
@ -46,6 +33,9 @@ typedef struct SArray {
|
|||
void* pData;
|
||||
} SArray;
|
||||
|
||||
#define TARRAY_SIZE(array) ((array)->size)
|
||||
#define TARRAY_DATA(array) ((array)->pData)
|
||||
|
||||
/**
|
||||
*
|
||||
* @param size
|
||||
|
|
|
@ -100,16 +100,17 @@ typedef struct {
|
|||
int32_t tRowBuild(SArray *aColVal, STSchema *pTSchema, SRow **ppRow) {
|
||||
int32_t code = 0;
|
||||
|
||||
ASSERT(taosArrayGetSize(aColVal) > 0);
|
||||
ASSERT(TARRAY_SIZE(aColVal) > 0);
|
||||
ASSERT(((SColVal *)aColVal->pData)[0].cid == PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||
ASSERT(((SColVal *)aColVal->pData)[0].type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
|
||||
// scan ---------------
|
||||
SRow *pRow = NULL;
|
||||
SColVal *colVals = (SColVal *)TARRAY_DATA(aColVal);
|
||||
uint8_t flag = 0;
|
||||
int32_t iColVal = 1;
|
||||
const int32_t nColVal = taosArrayGetSize(aColVal);
|
||||
SColVal *pColVal = (iColVal < nColVal) ? (SColVal *)taosArrayGet(aColVal, iColVal) : NULL;
|
||||
const int32_t nColVal = TARRAY_SIZE(aColVal);
|
||||
SColVal *pColVal = (iColVal < nColVal) ? &colVals[iColVal] : NULL;
|
||||
int32_t iTColumn = 1;
|
||||
STColumn *pTColumn = pTSchema->columns + iTColumn;
|
||||
int32_t ntp = 0;
|
||||
|
@ -142,13 +143,13 @@ int32_t tRowBuild(SArray *aColVal, STSchema *pTSchema, SRow **ppRow) {
|
|||
}
|
||||
|
||||
pTColumn = (++iTColumn < pTSchema->numOfCols) ? pTSchema->columns + iTColumn : NULL;
|
||||
pColVal = (++iColVal < nColVal) ? (SColVal *)taosArrayGet(aColVal, iColVal) : NULL;
|
||||
pColVal = (++iColVal < nColVal) ? &colVals[iColVal] : NULL;
|
||||
} else if (pColVal->cid > pTColumn->colId) { // NONE
|
||||
flag |= HAS_NONE;
|
||||
ntp += TYPE_BYTES[pTColumn->type];
|
||||
pTColumn = (++iTColumn < pTSchema->numOfCols) ? pTSchema->columns + iTColumn : NULL;
|
||||
} else {
|
||||
pColVal = (++iColVal < nColVal) ? (SColVal *)taosArrayGet(aColVal, iColVal) : NULL;
|
||||
pColVal = (++iColVal < nColVal) ? &colVals[iColVal] : NULL;
|
||||
}
|
||||
} else { // NONE
|
||||
flag |= HAS_NONE;
|
||||
|
@ -206,7 +207,7 @@ int32_t tRowBuild(SArray *aColVal, STSchema *pTSchema, SRow **ppRow) {
|
|||
}
|
||||
|
||||
// build --------------
|
||||
pColVal = (SColVal *)taosArrayGet(aColVal, 0);
|
||||
pColVal = &colVals[0];
|
||||
|
||||
pRow->flag = flag;
|
||||
pRow->rsv = 0;
|
||||
|
@ -219,7 +220,7 @@ int32_t tRowBuild(SArray *aColVal, STSchema *pTSchema, SRow **ppRow) {
|
|||
}
|
||||
|
||||
iColVal = 1;
|
||||
pColVal = (iColVal < nColVal) ? (SColVal *)taosArrayGet(aColVal, iColVal) : NULL;
|
||||
pColVal = (iColVal < nColVal) ? &colVals[iColVal] : NULL;
|
||||
iTColumn = 1;
|
||||
pTColumn = pTSchema->columns + iTColumn;
|
||||
if (flag >> 4) { // KV
|
||||
|
@ -271,11 +272,11 @@ int32_t tRowBuild(SArray *aColVal, STSchema *pTSchema, SRow **ppRow) {
|
|||
}
|
||||
|
||||
pTColumn = (++iTColumn < pTSchema->numOfCols) ? pTSchema->columns + iTColumn : NULL;
|
||||
pColVal = (++iColVal < nColVal) ? (SColVal *)taosArrayGet(aColVal, iColVal) : NULL;
|
||||
pColVal = (++iColVal < nColVal) ? &colVals[iColVal] : NULL;
|
||||
} else if (pColVal->cid > pTColumn->colId) { // NONE
|
||||
pTColumn = (++iTColumn < pTSchema->numOfCols) ? pTSchema->columns + iTColumn : NULL;
|
||||
} else {
|
||||
pColVal = (++iColVal < nColVal) ? (SColVal *)taosArrayGet(aColVal, iColVal) : NULL;
|
||||
pColVal = (++iColVal < nColVal) ? &colVals[iColVal] : NULL;
|
||||
}
|
||||
} else { // NONE
|
||||
pTColumn = (++iTColumn < pTSchema->numOfCols) ? pTSchema->columns + iTColumn : NULL;
|
||||
|
@ -337,13 +338,13 @@ int32_t tRowBuild(SArray *aColVal, STSchema *pTSchema, SRow **ppRow) {
|
|||
}
|
||||
|
||||
pTColumn = (++iTColumn < pTSchema->numOfCols) ? pTSchema->columns + iTColumn : NULL;
|
||||
pColVal = (++iColVal < nColVal) ? (SColVal *)taosArrayGet(aColVal, iColVal) : NULL;
|
||||
pColVal = (++iColVal < nColVal) ? &colVals[iColVal] : NULL;
|
||||
} else if (pColVal->cid > pTColumn->colId) { // NONE
|
||||
ROW_SET_BITMAP(pb, flag, iTColumn - 1, ROW_BIT_NONE);
|
||||
if (pf) memset(pf + pTColumn->offset, 0, TYPE_BYTES[pTColumn->type]);
|
||||
pTColumn = (++iTColumn < pTSchema->numOfCols) ? pTSchema->columns + iTColumn : NULL;
|
||||
} else {
|
||||
pColVal = (++iColVal < nColVal) ? (SColVal *)taosArrayGet(aColVal, iColVal) : NULL;
|
||||
pColVal = (++iColVal < nColVal) ? &colVals[iColVal] : NULL;
|
||||
}
|
||||
} else { // NONE
|
||||
ROW_SET_BITMAP(pb, flag, iTColumn - 1, ROW_BIT_NONE);
|
||||
|
|
|
@ -228,7 +228,7 @@ size_t taosArrayGetSize(const SArray* pArray) {
|
|||
if (pArray == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return pArray->size;
|
||||
return TARRAY_SIZE(pArray);
|
||||
}
|
||||
|
||||
void taosArraySetSize(SArray* pArray, size_t size) {
|
||||
|
|
Loading…
Reference in New Issue