summaryrefslogtreecommitdiff
path: root/src/backend/regex/regcomp.c
diff options
context:
space:
mode:
authorTatsuo Ishii <ishii@postgresql.org>2003-02-06 00:00:24 +0000
committerTatsuo Ishii <ishii@postgresql.org>2003-02-06 00:00:24 +0000
commitde42a5f53d9bb2fda1e6be9746023e56946c8b1f (patch)
tree74407f15da2d732c38f56f5edb41d10634288cce /src/backend/regex/regcomp.c
parent47729caf2d9a88a6aa5f0f7b609b95bf149c105b (diff)
Fix regexp slowness reported by Wade Klaver.
Diffstat (limited to 'src/backend/regex/regcomp.c')
-rw-r--r--src/backend/regex/regcomp.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/backend/regex/regcomp.c b/src/backend/regex/regcomp.c
index 71e69dea618..06c99139770 100644
--- a/src/backend/regex/regcomp.c
+++ b/src/backend/regex/regcomp.c
@@ -178,6 +178,9 @@ pg_regcomp(regex_t *preg, const char *pattern, int cflags)
int i;
size_t len;
pg_wchar *wcp;
+ size_t csetsize;
+
+ csetsize = (pg_database_encoding_max_length() == 1)?(SCHAR_MAX - SCHAR_MIN + 1):NC;
if (cclasses == NULL)
cclasses = cclass_init();
@@ -211,7 +214,7 @@ pg_regcomp(regex_t *preg, const char *pattern, int cflags)
/* do the mallocs early so failure handling is easy */
g = (struct re_guts *) malloc(sizeof(struct re_guts) +
- (NC - 1) * sizeof(cat_t));
+ (csetsize - 1) * sizeof(cat_t));
if (g == NULL)
return REG_ESPACE;
p->ssize = len / (size_t) 2 *(size_t) 3 + (size_t) 1; /* ugh */
@@ -235,7 +238,7 @@ pg_regcomp(regex_t *preg, const char *pattern, int cflags)
p->pbegin[i] = 0;
p->pend[i] = 0;
}
- g->csetsize = NC;
+ g->csetsize = csetsize;
g->sets = NULL;
g->setbits = NULL;
g->ncsets = 0;
@@ -248,7 +251,7 @@ pg_regcomp(regex_t *preg, const char *pattern, int cflags)
g->nsub = 0;
g->ncategories = 1; /* category 0 is "everything else" */
g->categories = &g->catspace[-(CHAR_MIN)];
- memset((char *) g->catspace, 0, NC * sizeof(cat_t));
+ memset((char *) g->catspace, 0, csetsize * sizeof(cat_t));
g->backrefs = 0;
/* do it */