From cfb1148c59e6a5406da7d60e7c24dd7fb9b331a5 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Tue, 25 Sep 2007 11:13:18 +0000 Subject: [PATCH] txid_snapshot_out: 1 less alloc, use PG_FREE_IF_COPY --- sql/txid/txid.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/sql/txid/txid.c b/sql/txid/txid.c index 6f85f128..5cc7a266 100644 --- a/sql/txid/txid.c +++ b/sql/txid/txid.c @@ -207,7 +207,7 @@ txid_current_snapshot(PG_FUNCTION_ARGS) for (i = 0; i < num; i++) snap->xip[i] = txid_convert_xid(SerializableSnapshot->xip[i], &state); - /* we want then guaranteed ascending order */ + /* we want them guaranteed ascending order */ sort_snapshot(snap); PG_RETURN_POINTER(snap); @@ -232,22 +232,26 @@ txid_snapshot_in(PG_FUNCTION_ARGS) Datum txid_snapshot_out(PG_FUNCTION_ARGS) { - TxidSnapshot *snap = (TxidSnapshot *) PG_GETARG_VARLENA_P(0); - StringInfo str; - int i; + TxidSnapshot *snap; + StringInfoData str; + int i; + + snap = (TxidSnapshot *) PG_GETARG_VARLENA_P(0); - str = makeStringInfo(); + initStringInfo(&str); - appendStringInfo(str, "%llu:", (unsigned long long)snap->xmin); - appendStringInfo(str, "%llu:", (unsigned long long)snap->xmax); + appendStringInfo(&str, "%llu:", (unsigned long long)snap->xmin); + appendStringInfo(&str, "%llu:", (unsigned long long)snap->xmax); for (i = 0; i < snap->nxip; i++) { - appendStringInfo(str, "%s%llu", ((i > 0) ? "," : ""), + appendStringInfo(&str, "%s%llu", ((i > 0) ? "," : ""), (unsigned long long)snap->xip[i]); } - PG_RETURN_CSTRING(str->data); + PG_FREE_IF_COPY(snap, 0); + + PG_RETURN_CSTRING(str.data); } -- 2.39.5