Re: Remove unnecessary static type qualifiers - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: Remove unnecessary static type qualifiers
Date
Msg-id 63425f7e-a08e-40b5-a4a7-fd2aee5ff101@eisentraut.org
Whole thread Raw
In response to Re: Remove unnecessary static type qualifiers  (Junwang Zhao <zhjwpku@gmail.com>)
Responses Re: Remove unnecessary static type qualifiers
List 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.




pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: Feature freeze
Next
From: Nathan Bossart
Date:
Subject: Re: Horribly slow pg_upgrade performance with many Large Objects