refactor
This commit is contained in:
parent
8d5d0fd4ef
commit
a0f3a9e268
|
@ -284,7 +284,35 @@ int tdInitKVRowBuilder(SKVRowBuilder *pBuilder);
|
||||||
void tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder);
|
void tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder);
|
||||||
void tdResetKVRowBuilder(SKVRowBuilder *pBuilder);
|
void tdResetKVRowBuilder(SKVRowBuilder *pBuilder);
|
||||||
SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder);
|
SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder);
|
||||||
int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, int8_t type, void *value);
|
|
||||||
|
static FORCE_INLINE int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, int8_t type, void *value) {
|
||||||
|
ASSERT(pBuilder->nCols == 0 || colId > pBuilder->pColIdx[pBuilder->nCols - 1].colId);
|
||||||
|
|
||||||
|
if (pBuilder->nCols >= pBuilder->tCols) {
|
||||||
|
pBuilder->tCols *= 2;
|
||||||
|
pBuilder->pColIdx = (SColIdx *)realloc((void *)(pBuilder->pColIdx), sizeof(SColIdx) * pBuilder->tCols);
|
||||||
|
if (pBuilder->pColIdx == NULL) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pBuilder->pColIdx[pBuilder->nCols].colId = colId;
|
||||||
|
pBuilder->pColIdx[pBuilder->nCols].offset = pBuilder->size;
|
||||||
|
|
||||||
|
pBuilder->nCols++;
|
||||||
|
|
||||||
|
int tlen = IS_VAR_DATA_TYPE(type) ? varDataTLen(value) : TYPE_BYTES[type];
|
||||||
|
if (tlen > pBuilder->alloc - pBuilder->size) {
|
||||||
|
while (tlen > pBuilder->alloc - pBuilder->size) {
|
||||||
|
pBuilder->alloc *= 2;
|
||||||
|
}
|
||||||
|
pBuilder->buf = realloc(pBuilder->buf, pBuilder->alloc);
|
||||||
|
if (pBuilder->buf == NULL) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(POINTER_SHIFT(pBuilder->buf, pBuilder->size), value, tlen);
|
||||||
|
pBuilder->size += tlen;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------- Tag row structure
|
// ----------------- Tag row structure
|
||||||
|
|
||||||
|
|
|
@ -721,33 +721,4 @@ SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder) {
|
||||||
memcpy(kvRowValues(row), pBuilder->buf, pBuilder->size);
|
memcpy(kvRowValues(row), pBuilder->buf, pBuilder->size);
|
||||||
|
|
||||||
return row;
|
return row;
|
||||||
}
|
|
||||||
|
|
||||||
int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, int8_t type, void *value) {
|
|
||||||
ASSERT(pBuilder->nCols == 0 || colId > pBuilder->pColIdx[pBuilder->nCols - 1].colId);
|
|
||||||
|
|
||||||
if (pBuilder->nCols >= pBuilder->tCols) {
|
|
||||||
pBuilder->tCols *= 2;
|
|
||||||
pBuilder->pColIdx = realloc(pBuilder->pColIdx, sizeof(SColIdx) * pBuilder->tCols);
|
|
||||||
if (pBuilder->pColIdx == NULL) return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pBuilder->pColIdx[pBuilder->nCols].colId = colId;
|
|
||||||
pBuilder->pColIdx[pBuilder->nCols].offset = pBuilder->size;
|
|
||||||
|
|
||||||
pBuilder->nCols++;
|
|
||||||
|
|
||||||
int tlen = IS_VAR_DATA_TYPE(type) ? varDataTLen(value) : TYPE_BYTES[type];
|
|
||||||
if (tlen > pBuilder->alloc - pBuilder->size) {
|
|
||||||
while (tlen > pBuilder->alloc - pBuilder->size) {
|
|
||||||
pBuilder->alloc *= 2;
|
|
||||||
}
|
|
||||||
pBuilder->buf = realloc(pBuilder->buf, pBuilder->alloc);
|
|
||||||
if (pBuilder->buf == NULL) return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(POINTER_SHIFT(pBuilder->buf, pBuilder->size), value, tlen);
|
|
||||||
pBuilder->size += tlen;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue