From 5e7d43c2cddca9dd31c690c0ff6f83b0fecf4530 Mon Sep 17 00:00:00 2001 From: Kyryl Melekhin Date: Tue, 14 Dec 2021 15:30:16 +0000 Subject: [PATCH] improve matched condition --- pike.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pike.c b/pike.c index 394635b..3ce0334 100644 --- a/pike.c +++ b/pike.c @@ -482,6 +482,17 @@ else if (spc == JMP) { \ goto rec##nn; \ } \ +#define clistmatch() +#define nlistmatch() \ +if (*npc == MATCH) \ + for (i++; i < clistidx; i++) { \ + npc = clist[i].pc; \ + nsub = clist[i].sub; \ + if (*npc == MATCH) \ + goto matched; \ + decref(nsub) \ + } \ + #define addthread(nn, list, listidx) \ si = 0; \ rec##nn: \ @@ -495,6 +506,7 @@ if ((unsigned int)spc < WBEG) { \ nsub = subs[si]; \ goto rec##nn; \ } \ + list##match() \ continue; \ } \ next##nn: \ @@ -556,9 +568,8 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp) rsub *subs[prog->splits]; char nsubs[rsubsize * (prog->len-prog->splits+14)]; rsub *nsub, *s1, *matched = NULL, *freesub = NULL; - rthread _clist[prog->len+1], _nlist[prog->len+1]; - _clist[0].pc = insts, _nlist[0].pc = insts; - rthread *clist = _clist+1, *nlist = _nlist+1, *tmp; + rthread _clist[prog->len], _nlist[prog->len]; + rthread *clist = _clist, *nlist = _nlist, *tmp; goto jmp_start; for (;; sp = _sp) { uc_len(i, sp) uc_code(c, sp) @@ -577,6 +588,7 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp) deccont() npc += *(npc+2) * 2 + 3; } else if (spc == MATCH) { + matched: nlist[nlistidx++].pc = &mcont; if (npc != &mcont) { if (matched) { @@ -596,8 +608,6 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp) goto _continue; } else npc++; - if (*nlist[nlistidx-1].pc == MATCH) - deccont() addthread(2, nlist, nlistidx) } if (sp == _sp)