Re: Proposal: add new API to stringinfo

Nathan Bossart <nathandbossart@gmail.com>

From: Nathan Bossart <nathandbossart@gmail.com>
To: Tatsuo Ishii <ishii@postgresql.org>
Cc: dgrowleyml@gmail.com, gurjeet@singh.im, pgsql-hackers@postgresql.org, michael@paquier.xyz, andrew@dunslane.net
Date: 2025-01-09T23:27:03Z
Lists: pgsql-hackers
On Thu, Jan 09, 2025 at 03:21:41PM +0900, Tatsuo Ishii wrote:
> Ok, I have created v3 patch to do more inlining as you suggested. With
> the patch I confirmed that there's no call to functions except palloc
> in makeStringInfo, makeStringInfoExt, initStringInfo and
> initStringInfoExt in the asm codes (see attached stringinfo.s).

Looks generally reasonable to me.

+/*
+ * initStringInfoInternal
+ *
+ * Initialize a StringInfoData struct (with previously undefined contents)
+ * to describe an empty string.
+ * The initial memory allocation size is specified by 'initsize'.
+ * The valid range for 'initsize' is 1 to MaxAllocSize.
+ */
+static inline void
+initStringInfoInternal(StringInfo str, int initsize)
+{
+	Assert(initsize > 0);
+
+	str->data = (char *) palloc(initsize);
+	str->maxlen = initsize;
+	resetStringInfo(str);
+}

nitpick: Should we Assert(initsize <= MaxAllocSize) here, too?

-- 
nathan



Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Add new StringInfo APIs to allow callers to specify the buffer size.