1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-07 00:36:50 +03:00

Speed up conversion of signed integers to C strings.

A hand-coded implementation turns out to be much faster than calling
printf().  In passing, add a few more regresion tests.

Andres Freund, with assorted, mostly cosmetic changes.
This commit is contained in:
Robert Haas
2010-11-19 22:13:11 -05:00
parent 0f61d4dd1b
commit 4fc115b2e9
9 changed files with 157 additions and 18 deletions

View File

@ -20,6 +20,7 @@
#include "funcapi.h"
#include "libpq/pqformat.h"
#include "utils/int8.h"
#include "utils/builtins.h"
#define MAXINT8LEN 25
@ -157,13 +158,10 @@ Datum
int8out(PG_FUNCTION_ARGS)
{
int64 val = PG_GETARG_INT64(0);
char *result;
int len;
char buf[MAXINT8LEN + 1];
char *result;
if ((len = snprintf(buf, MAXINT8LEN, INT64_FORMAT, val)) < 0)
elog(ERROR, "could not format int8");
pg_lltoa(val, buf);
result = pstrdup(buf);
PG_RETURN_CSTRING(result);
}