From 27704df09917d797cfdc5c86446f2f28a066ca0b Mon Sep 17 00:00:00 2001 From: Kyryl Melekhin Date: Sat, 31 Jul 2021 11:06:40 +0000 Subject: [PATCH] use frexible array for nsubs cache --- pike.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pike.c b/pike.c index f25effb..233dd7e 100644 --- a/pike.c +++ b/pike.c @@ -101,7 +101,7 @@ typedef struct rsub rsub; struct rsub { int ref; - const char *sub[128]; + const char *sub[]; }; typedef struct rthread rthread; @@ -455,7 +455,7 @@ if (csub->ref > 1) { \ if (s1) \ freesub = (rsub*)s1->sub[0]; \ else \ - s1 = &nsubs[subidx++]; \ + s1 = (rsub*)&nsubs[rsubsize * subidx++]; \ for (j = 0; j < nsubp; j++) \ s1->sub[j] = csub->sub[j]; \ csub->ref--; \ @@ -532,12 +532,13 @@ nlist->n = 0; \ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp) { int i, j, c, l = 0, *npc, gen = 1, subidx = 1; + int rsubsize = sizeof(rsub)+(sizeof(char*)*nsubp); const char *sp = s; - rsub nsubs[256]; int plist[prog->unilen]; int *pcs[prog->splits]; rsub *subs[prog->splits]; - rsub *nsub = nsubs, *lsub = nsub, *matched = NULL, *s1; + char nsubs[rsubsize*256]; + rsub *nsub = (rsub*)nsubs, *lsub = nsub, *matched = NULL, *s1; rsub *freesub = NULL; rthreadlist _clist[1+prog->len]; rthreadlist _nlist[1+prog->len];