From 47ef1fd6d2e0724251e50202e72da5fa6de95f16 Mon Sep 17 00:00:00 2001 From: Kyryl Melekhin Date: Tue, 3 Aug 2021 21:41:49 +0000 Subject: [PATCH] misc: don't put matching lsub into sub pool --- pike.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/pike.c b/pike.c index eedfcaa..f6d9785 100644 --- a/pike.c +++ b/pike.c @@ -447,19 +447,16 @@ int re_comp(rcode *prog, const char *re) return RE_SUCCESS; } -#define newsub(csub) \ -if (csub->ref > 1) { \ - s1 = freesub; \ - if (s1) \ - freesub = (rsub*)s1->sub[0]; \ - else \ - s1 = (rsub*)&nsubs[rsubsize * subidx++]; \ - for (j = 0; j < nsubp; j++) \ - s1->sub[j] = csub->sub[j]; \ - csub->ref--; \ - csub = s1; \ - csub->ref = 1; \ -} \ +#define newsub(n, csub) \ +s1 = freesub; \ +if (s1) \ + freesub = (rsub*)s1->sub[0]; \ +else \ + s1 = (rsub*)&nsubs[rsubsize * subidx++]; \ +for (j = n; j < nsubp; j++) \ + s1->sub[j] = csub->sub[j]; \ +csub = s1; \ +csub->ref = 1; \ #define decref(csub) \ if (--csub->ref == 0) { \ @@ -509,7 +506,10 @@ if (--csub->ref == 0) { \ pc += pc[-1]; \ goto rec##nn; \ case SAVE: \ - newsub(sub) \ + if (sub->ref > 1) { \ + sub->ref--; \ + newsub(0, sub) \ + } \ sub->sub[pc[1]] = _sp; \ pc += 2; \ goto rec##nn; \ @@ -549,13 +549,12 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp) rthread *clist = _clist, *nlist = _nlist, *tmp; memset(plist, 0, prog->unilen*sizeof(plist[0])); - for(i=0; isub[i] = NULL; } gen = 1; - nsub->ref = 2; goto jmp_start; for(;; sp += l) { gen++; uc_len(l, sp) uc_code(c, sp) @@ -591,16 +590,15 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp) nlistidx = 0; if (!matched) { nsub = lsub; - nsub->ref++; jmp_start: - newsub(nsub) + newsub(1, nsub) nsub->sub[0] = sp + l; addthread(1, clist, clistidx, insts, nsub) } else if (!clistidx) break; } if(matched) { - for(i=0; isub[i]; return 1; }