diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-01-18 16:04:11 -0500 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-01-18 16:04:32 -0500 |
| commit | 0d79c0a8cc20dbaa39112d78a9abb821c4ca3554 (patch) | |
| tree | fbf44e5fc488b94c056aead354111d4e32167318 /src/include/mb | |
| parent | 7d7eee8bb702d7796a0d7c5886c1f4685f2e2806 (diff) | |
| download | postgresql-0d79c0a8cc20dbaa39112d78a9abb821c4ca3554.tar.gz | |
Make various variables const (read-only).
These changes should generally improve correctness/maintainability.
A nice side benefit is that several kilobytes move from initialized
data to text segment, allowing them to be shared across processes and
probably reducing copy-on-write overhead while forking a new backend.
Unfortunately this doesn't seem to help libpq in the same way (at least
not when it's compiled with -fpic on x86_64), but we can hope the linker
at least collects all nominally-const data together even if it's not
actually part of the text segment.
Also, make pg_encname_tbl[] static in encnames.c, since there seems
no very good reason for any other code to use it; per a suggestion
from Wim Lewis, who independently submitted a patch that was mostly
a subset of this one.
Oskari Saarenmaa, with some editorialization by me
Diffstat (limited to 'src/include/mb')
| -rw-r--r-- | src/include/mb/pg_wchar.h | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/src/include/mb/pg_wchar.h b/src/include/mb/pg_wchar.h index 74aacc4368..6154d20969 100644 --- a/src/include/mb/pg_wchar.h +++ b/src/include/mb/pg_wchar.h @@ -303,33 +303,23 @@ typedef enum pg_enc #define PG_VALID_FE_ENCODING(_enc) PG_VALID_ENCODING(_enc) /* - * Encoding names with all aliases - */ -typedef struct pg_encname -{ - char *name; - pg_enc encoding; -} pg_encname; - -extern pg_encname pg_encname_tbl[]; -extern unsigned int pg_encname_tbl_sz; - -/* - * Careful: + * Table for mapping an encoding number to official encoding name and + * possibly other subsidiary data. Be careful to check encoding number + * before accessing a table entry! * * if (PG_VALID_ENCODING(encoding)) * pg_enc2name_tbl[ encoding ]; */ typedef struct pg_enc2name { - char *name; + const char *name; pg_enc encoding; #ifdef WIN32 unsigned codepage; /* codepage for WIN32 */ #endif } pg_enc2name; -extern pg_enc2name pg_enc2name_tbl[]; +extern const pg_enc2name pg_enc2name_tbl[]; /* * Encoding names for gettext @@ -340,7 +330,7 @@ typedef struct pg_enc2gettext const char *name; } pg_enc2gettext; -extern pg_enc2gettext pg_enc2gettext_tbl[]; +extern const pg_enc2gettext pg_enc2gettext_tbl[]; /* * pg_wchar stuff @@ -373,7 +363,7 @@ typedef struct int maxmblen; /* max bytes for a char in this encoding */ } pg_wchar_tbl; -extern pg_wchar_tbl pg_wchar_table[]; +extern const pg_wchar_tbl pg_wchar_table[]; /* * UTF-8 to local code conversion map @@ -441,8 +431,6 @@ extern int pg_valid_server_encoding_id(int encoding); * Remaining functions are not considered part of libpq's API, though many * of them do exist inside libpq. */ -extern pg_encname *pg_char_to_encname_struct(const char *name); - extern int pg_mb2wchar(const char *from, pg_wchar *to); extern int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len); extern int pg_encoding_mb2wchar_with_len(int encoding, |
