misc: don't put matching lsub into sub pool

This commit is contained in:
Kyryl Melekhin
2021-08-03 21:41:49 +00:00
parent afe0b781d0
commit 47ef1fd6d2

30
pike.c
View File

@@ -447,19 +447,16 @@ int re_comp(rcode *prog, const char *re)
return RE_SUCCESS; return RE_SUCCESS;
} }
#define newsub(csub) \ #define newsub(n, csub) \
if (csub->ref > 1) { \ s1 = freesub; \
s1 = freesub; \ if (s1) \
if (s1) \
freesub = (rsub*)s1->sub[0]; \ freesub = (rsub*)s1->sub[0]; \
else \ else \
s1 = (rsub*)&nsubs[rsubsize * subidx++]; \ s1 = (rsub*)&nsubs[rsubsize * subidx++]; \
for (j = 0; j < nsubp; j++) \ for (j = n; j < nsubp; j++) \
s1->sub[j] = csub->sub[j]; \ s1->sub[j] = csub->sub[j]; \
csub->ref--; \ csub = s1; \
csub = s1; \ csub->ref = 1; \
csub->ref = 1; \
} \
#define decref(csub) \ #define decref(csub) \
if (--csub->ref == 0) { \ if (--csub->ref == 0) { \
@@ -509,7 +506,10 @@ if (--csub->ref == 0) { \
pc += pc[-1]; \ pc += pc[-1]; \
goto rec##nn; \ goto rec##nn; \
case SAVE: \ case SAVE: \
newsub(sub) \ if (sub->ref > 1) { \
sub->ref--; \
newsub(0, sub) \
} \
sub->sub[pc[1]] = _sp; \ sub->sub[pc[1]] = _sp; \
pc += 2; \ pc += 2; \
goto rec##nn; \ 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; rthread *clist = _clist, *nlist = _nlist, *tmp;
memset(plist, 0, prog->unilen*sizeof(plist[0])); memset(plist, 0, prog->unilen*sizeof(plist[0]));
for(i=0; i<nsubp; i++) { for(i = 0; i < nsubp; i++) {
subp[i] = NULL; subp[i] = NULL;
nsub->sub[i] = NULL; nsub->sub[i] = NULL;
} }
gen = 1; gen = 1;
nsub->ref = 2;
goto jmp_start; goto jmp_start;
for(;; sp += l) { for(;; sp += l) {
gen++; uc_len(l, sp) uc_code(c, sp) 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; nlistidx = 0;
if (!matched) { if (!matched) {
nsub = lsub; nsub = lsub;
nsub->ref++;
jmp_start: jmp_start:
newsub(nsub) newsub(1, nsub)
nsub->sub[0] = sp + l; nsub->sub[0] = sp + l;
addthread(1, clist, clistidx, insts, nsub) addthread(1, clist, clistidx, insts, nsub)
} else if (!clistidx) } else if (!clistidx)
break; break;
} }
if(matched) { if(matched) {
for(i=0; i<nsubp; i++) for(i = 0; i < nsubp; i++)
subp[i] = matched->sub[i]; subp[i] = matched->sub[i];
return 1; return 1;
} }