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.