diff options
author | Michael Paquier <michael@paquier.xyz> | 2024-03-01 18:03:48 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2024-03-01 18:03:48 +0900 |
commit | 655dc310460c601d434d05339b7fa46ed97675b3 (patch) | |
tree | 9c502f28b148dea717d2f41ed14f541198dea806 /src/backend/utils/mb/mbutils.c | |
parent | def0ce3370689b939c6d7a3c3eb824d69989ef6e (diff) |
Simplify pg_enc2gettext_tbl[] with C99-designated initializer syntax
This commit switches pg_enc2gettext_tbl[] in encnames.c to use a
C99-designated initializer syntax.
pg_bind_textdomain_codeset() is simplified so as it is possible to do
a direct lookup at the gettext() array with a value of the enum pg_enc
rather than doing a loop through all its elements, as long as the
encoding value provided by GetDatabaseEncoding() is in the correct range
of supported encoding values. Note that PG_MULE_INTERNAL gains a value
in the array, pointing to NULL.
Author: Jelte Fennema-Nio
Discussion: https://postgr.es/m/CAGECzQT3caUbcCcszNewCCmMbCuyP7XNAm60J3ybd6PN5kH2Dw@mail.gmail.com
Diffstat (limited to 'src/backend/utils/mb/mbutils.c')
-rw-r--r-- | src/backend/utils/mb/mbutils.c | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c index c13f947a827..7108ab89836 100644 --- a/src/backend/utils/mb/mbutils.c +++ b/src/backend/utils/mb/mbutils.c @@ -1188,24 +1188,18 @@ static bool raw_pg_bind_textdomain_codeset(const char *domainname, int encoding) { bool elog_ok = (CurrentMemoryContext != NULL); - int i; - for (i = 0; pg_enc2gettext_tbl[i].name != NULL; i++) - { - if (pg_enc2gettext_tbl[i].encoding == encoding) - { - if (bind_textdomain_codeset(domainname, - pg_enc2gettext_tbl[i].name) != NULL) - return true; + if (!PG_VALID_ENCODING(encoding) || pg_enc2gettext_tbl[encoding] == NULL) + return false; - if (elog_ok) - elog(LOG, "bind_textdomain_codeset failed"); - else - write_stderr("bind_textdomain_codeset failed"); + if (bind_textdomain_codeset(domainname, + pg_enc2gettext_tbl[encoding]) != NULL) + return true; - break; - } - } + if (elog_ok) + elog(LOG, "bind_textdomain_codeset failed"); + else + write_stderr("bind_textdomain_codeset failed"); return false; } |