From e38cd6098a1c787cb3a3ffce9693c7b229b87792 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Fri, 28 Jan 2022 21:06:36 +0000 Subject: [PATCH] libast/regex: do not use small block size for stack (re: e311f1e6) Opening the match stack with the STK_SMALL flag causes the stk code to allocate memory in blocks of 64*sizeof(char*) instead of 1024*sizeof(char*). This caused a significant slowdown which was exposed by the extglob.ksh module of shbench. Thanks to @JohnoKing for noticing and reporting the problem. src/lib/libast/regex/regcomp.c: regcomp(): - Remove STK_SMALL from the stkopen() option bit flags. Resolves: https://github.com/ksh93/ksh/issues/440 --- src/lib/libast/regex/regcomp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/libast/regex/regcomp.c b/src/lib/libast/regex/regcomp.c index 060b5ea8..acb88be7 100644 --- a/src/lib/libast/regex/regcomp.c +++ b/src/lib/libast/regex/regcomp.c @@ -3278,7 +3278,7 @@ regcomp(regex_t* p, const char* pattern, regflags_t flags) if (!(p->env = (Env_t*)alloc(disc, 0, sizeof(Env_t)))) return fatal(disc, REG_ESPACE, pattern); memset(p->env, 0, sizeof(*p->env)); - if (!(p->env->mst = stkopen(STK_SMALL|STK_NULL))) + if (!(p->env->mst = stkopen(STK_NULL))) return fatal(disc, REG_ESPACE, pattern); memset(&env, 0, sizeof(env)); env.regex = p;