mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-10 22:56:55 +08:00
Improved halfvec_out code [skip ci]
This commit is contained in:
@@ -478,6 +478,9 @@ halfvec_in(PG_FUNCTION_ARGS)
|
|||||||
PG_RETURN_POINTER(result);
|
PG_RETURN_POINTER(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define AppendChar(ptr, c) (*(ptr)++ = (c))
|
||||||
|
#define AppendFloat(ptr, f) ((ptr) += float_to_shortest_decimal_bufn((f), (ptr)))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert internal representation to textual representation
|
* Convert internal representation to textual representation
|
||||||
*/
|
*/
|
||||||
@@ -489,7 +492,6 @@ halfvec_out(PG_FUNCTION_ARGS)
|
|||||||
int dim = vector->dim;
|
int dim = vector->dim;
|
||||||
char *buf;
|
char *buf;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int n;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Need:
|
* Need:
|
||||||
@@ -504,21 +506,17 @@ halfvec_out(PG_FUNCTION_ARGS)
|
|||||||
buf = (char *) palloc(FLOAT_SHORTEST_DECIMAL_LEN * dim + 2);
|
buf = (char *) palloc(FLOAT_SHORTEST_DECIMAL_LEN * dim + 2);
|
||||||
ptr = buf;
|
ptr = buf;
|
||||||
|
|
||||||
*ptr = '[';
|
AppendChar(ptr, '[');
|
||||||
ptr++;
|
|
||||||
for (int i = 0; i < dim; i++)
|
for (int i = 0; i < dim; i++)
|
||||||
{
|
{
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
{
|
AppendChar(ptr, ',');
|
||||||
*ptr = ',';
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
n = float_to_shortest_decimal_bufn(HalfToFloat4(vector->x[i]), ptr);
|
AppendFloat(ptr, HalfToFloat4(vector->x[i]));
|
||||||
ptr += n;
|
|
||||||
}
|
}
|
||||||
*ptr = ']';
|
|
||||||
ptr++;
|
AppendChar(ptr, ']');
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
|
|
||||||
PG_FREE_IF_COPY(vector, 0);
|
PG_FREE_IF_COPY(vector, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user