From: | Peter Eisentraut <peter(at)eisentraut(dot)org> |
---|---|
To: | Junwang Zhao <zhjwpku(at)gmail(dot)com>, Japin Li <japinli(at)hotmail(dot)com> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Remove unnecessary static type qualifiers |
Date: | 2025-04-08 15:46:21 |
Message-ID: | 63425f7e-a08e-40b5-a4a7-fd2aee5ff101@eisentraut.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 08.04.25 14:22, Junwang Zhao wrote:
>> When I read the libpq source code, I found unnecessary static type qualifiers
>> in PQsetClientEncoding().
>>
>> diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
>> index 0258d9ace3c..300ddfffd55 100644
>> --- a/src/interfaces/libpq/fe-connect.c
>> +++ b/src/interfaces/libpq/fe-connect.c
>> @@ -7717,7 +7717,7 @@ int
>> PQsetClientEncoding(PGconn *conn, const char *encoding)
>> {
>> char qbuf[128];
>> - static const char query[] = "set client_encoding to '%s'";
>> + const char query[] = "set client_encoding to '%s'";
>> PGresult *res;
>> int status;
>>
>
> I doubt that, if you remove the *static*, it will allocate more memory
> on stack and need more instructions to copy the string to that area.
To avoid creating an array on the stack, you could maybe write it with a
pointer instead, like:
const char * const query = "...";
I haven't tested whether that results in different or better compiled
code. The original code is probably good enough.
From | Date | Subject | |
---|---|---|---|
Next Message | Nathan Bossart | 2025-04-08 15:46:41 | Re: Horribly slow pg_upgrade performance with many Large Objects |
Previous Message | Peter Geoghegan | 2025-04-08 15:45:09 | Re: Feature freeze |