1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-28 11:44:57 +03:00

Fix regexp slowness reported by Wade Klaver.

This commit is contained in:
Tatsuo Ishii
2003-02-06 00:00:24 +00:00
parent 47729caf2d
commit de42a5f53d

View File

@@ -178,6 +178,9 @@ pg_regcomp(regex_t *preg, const char *pattern, int cflags)
int i; int i;
size_t len; size_t len;
pg_wchar *wcp; pg_wchar *wcp;
size_t csetsize;
csetsize = (pg_database_encoding_max_length() == 1)?(SCHAR_MAX - SCHAR_MIN + 1):NC;
if (cclasses == NULL) if (cclasses == NULL)
cclasses = cclass_init(); 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 */ /* do the mallocs early so failure handling is easy */
g = (struct re_guts *) malloc(sizeof(struct re_guts) + g = (struct re_guts *) malloc(sizeof(struct re_guts) +
(NC - 1) * sizeof(cat_t)); (csetsize - 1) * sizeof(cat_t));
if (g == NULL) if (g == NULL)
return REG_ESPACE; return REG_ESPACE;
p->ssize = len / (size_t) 2 *(size_t) 3 + (size_t) 1; /* ugh */ 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->pbegin[i] = 0;
p->pend[i] = 0; p->pend[i] = 0;
} }
g->csetsize = NC; g->csetsize = csetsize;
g->sets = NULL; g->sets = NULL;
g->setbits = NULL; g->setbits = NULL;
g->ncsets = 0; g->ncsets = 0;
@@ -248,7 +251,7 @@ pg_regcomp(regex_t *preg, const char *pattern, int cflags)
g->nsub = 0; g->nsub = 0;
g->ncategories = 1; /* category 0 is "everything else" */ g->ncategories = 1; /* category 0 is "everything else" */
g->categories = &g->catspace[-(CHAR_MIN)]; 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; g->backrefs = 0;
/* do it */ /* do it */