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/backend/regex | |
parent | 7d7eee8bb702d7796a0d7c5886c1f4685f2e2806 (diff) | |
download | postgresql-0d79c0a8cc20dbaa39112d78a9abb821c4ca3554.tar.gz postgresql-0d79c0a8cc20dbaa39112d78a9abb821c4ca3554.zip |
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/backend/regex')
-rw-r--r-- | src/backend/regex/regc_lex.c | 4 | ||||
-rw-r--r-- | src/backend/regex/regcomp.c | 2 | ||||
-rw-r--r-- | src/backend/regex/regerror.c | 6 |
3 files changed, 6 insertions, 6 deletions
diff --git a/src/backend/regex/regc_lex.c b/src/backend/regex/regc_lex.c index 3360cfb0e9f..c4095e98cbd 100644 --- a/src/backend/regex/regc_lex.c +++ b/src/backend/regex/regc_lex.c @@ -716,10 +716,10 @@ static int /* not actually used, but convenient for RETV */ lexescape(struct vars * v) { chr c; - static chr alert[] = { + static const chr alert[] = { CHR('a'), CHR('l'), CHR('e'), CHR('r'), CHR('t') }; - static chr esc[] = { + static const chr esc[] = { CHR('E'), CHR('S'), CHR('C') }; const chr *save; diff --git a/src/backend/regex/regcomp.c b/src/backend/regex/regcomp.c index b5988a2fbc1..ca1ccc52023 100644 --- a/src/backend/regex/regcomp.c +++ b/src/backend/regex/regcomp.c @@ -274,7 +274,7 @@ struct vars /* static function list */ -static struct fns functions = { +static const struct fns functions = { rfree, /* regfree insides */ }; diff --git a/src/backend/regex/regerror.c b/src/backend/regex/regerror.c index f6a3f2667f8..4b2573e6255 100644 --- a/src/backend/regex/regerror.c +++ b/src/backend/regex/regerror.c @@ -34,10 +34,10 @@ #include "regex/regguts.h" /* unknown-error explanation */ -static char unk[] = "*** unknown regex error code 0x%x ***"; +static const char unk[] = "*** unknown regex error code 0x%x ***"; /* struct to map among codes, code names, and explanations */ -static struct rerr +static const struct rerr { int code; const char *name; @@ -62,7 +62,7 @@ pg_regerror(int errcode, /* error code, or REG_ATOI or REG_ITOA */ char *errbuf, /* result buffer (unless errbuf_size==0) */ size_t errbuf_size) /* available space in errbuf, can be 0 */ { - struct rerr *r; + const struct rerr *r; const char *msg; char convbuf[sizeof(unk) + 50]; /* 50 = plenty for int */ size_t len; |