Re: Remove unnecessary static type qualifiers
От | Peter Eisentraut |
---|---|
Тема | Re: Remove unnecessary static type qualifiers |
Дата | |
Msg-id | 63425f7e-a08e-40b5-a4a7-fd2aee5ff101@eisentraut.org обсуждение исходный текст |
Ответ на | Re: Remove unnecessary static type qualifiers (Junwang Zhao <zhjwpku@gmail.com>) |
Ответы |
Re: Remove unnecessary static type qualifiers
|
Список | 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 по дате отправления: