Use stack-allocated StringInfoData
Mats Kindahl <mats.kindahl@gmail.com>
From: Mats Kindahl <mats.kindahl@gmail.com>
To: pgsql-hackers@lists.postgresql.org
Date: 2025-11-03T07:27:12Z
Lists: pgsql-hackers
Attachments
- 0001-Use-stack-allocated-StringInfoData.v1.patch (text/x-patch)
Hi all, While working on other things I noted that we have a lot of cases where a StringInfo instance is allocated dynamically even when it is either thrown away or destroyed at the end, which seems unnecessary, that is, instead of using: StringInfo info = makeStringInfo(); ... appendStringInfo(info, ...); ... return info->data; We can use StringInfoData info; initStringInfo(&info); ... appendStringInfo(&info, ...); ... return info.data; It was corrected in an earlier commit, but that seems to have been removed so we still have a lot of these cases. I created a semantic patch to capture most of these cases, which is present in [1], but this is a slightly modified version that might be interesting to include regardless of other changes. The patch is applied and one case that couldn't be matched is manually fixed. [1]: https://www.postgresql.org/message-id/8895cba9-48cf-40fe-9c47-9b43ec6b2ab3%40gmail.com Best wishes, Mats Kindahl