pgsql: Use stack allocated StringInfoDatas, where possible

From: David Rowley <drowley(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Use stack allocated StringInfoDatas, where possible
Date: 2025-11-06 02:00:08
Message-ID: E1vGpIG-005Dnm-2W@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Use stack allocated StringInfoDatas, where possible

Various places that were using StringInfo but didn't need that
StringInfo to exist beyond the scope of the function were using
makeStringInfo(), which allocates both a StringInfoData and the buffer it
uses as two separate allocations. It's more efficient for these cases to
use a StringInfoData on the stack and initialize it with initStringInfo(),
which only allocates the string buffer. This also simplifies the cleanup,
in a few cases.

Author: Mats Kindahl <mats(dot)kindahl(at)gmail(dot)com>
Reviewed-by: David Rowley <dgrowleyml(at)gmail(dot)com>
Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Discussion: https://postgr.es/m/4379aac8-26f1-42f2-a356-ff0e886228d3@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6d0eba66275b125bf634bbdffda90c70856e3f93

Modified Files
--------------
contrib/postgres_fdw/postgres_fdw.c | 14 ++++-----
contrib/tcn/tcn.c | 19 ++++++------
src/backend/access/transam/xlogbackup.c | 34 ++++++++++-----------
src/backend/backup/basebackup.c | 10 +++----
src/backend/commands/subscriptioncmds.c | 35 ++++++++++++----------
src/backend/utils/adt/json.c | 53 +++++++++++++++++----------------
src/backend/utils/adt/jsonb.c | 9 +++---
src/backend/utils/adt/jsonfuncs.c | 18 +++++++----
src/backend/utils/adt/multirangetypes.c | 13 ++++----
src/backend/utils/adt/rangetypes.c | 18 ++++++-----
src/backend/utils/adt/ruleutils.c | 17 ++++++-----
src/backend/utils/adt/xml.c | 34 ++++++++++-----------
12 files changed, 144 insertions(+), 130 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message David Rowley 2025-11-06 03:03:40 pgsql: Doc: use uppercase keywords in SQLs
Previous Message Thomas Munro 2025-11-06 01:28:48 pgsql: ci: Add missing "set -e" to scripts run by su.