improve matched condition

This commit is contained in:
Kyryl Melekhin
2021-12-14 15:30:16 +00:00
parent 90401ebfae
commit 5e7d43c2cd

20
pike.c
View File

@@ -482,6 +482,17 @@ else if (spc == JMP) { \
goto rec##nn; \ 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) \ #define addthread(nn, list, listidx) \
si = 0; \ si = 0; \
rec##nn: \ rec##nn: \
@@ -495,6 +506,7 @@ if ((unsigned int)spc < WBEG) { \
nsub = subs[si]; \ nsub = subs[si]; \
goto rec##nn; \ goto rec##nn; \
} \ } \
list##match() \
continue; \ continue; \
} \ } \
next##nn: \ next##nn: \
@@ -556,9 +568,8 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
rsub *subs[prog->splits]; rsub *subs[prog->splits];
char nsubs[rsubsize * (prog->len-prog->splits+14)]; char nsubs[rsubsize * (prog->len-prog->splits+14)];
rsub *nsub, *s1, *matched = NULL, *freesub = NULL; rsub *nsub, *s1, *matched = NULL, *freesub = NULL;
rthread _clist[prog->len+1], _nlist[prog->len+1]; rthread _clist[prog->len], _nlist[prog->len];
_clist[0].pc = insts, _nlist[0].pc = insts; rthread *clist = _clist, *nlist = _nlist, *tmp;
rthread *clist = _clist+1, *nlist = _nlist+1, *tmp;
goto jmp_start; goto jmp_start;
for (;; sp = _sp) { for (;; sp = _sp) {
uc_len(i, sp) uc_code(c, 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() deccont()
npc += *(npc+2) * 2 + 3; npc += *(npc+2) * 2 + 3;
} else if (spc == MATCH) { } else if (spc == MATCH) {
matched:
nlist[nlistidx++].pc = &mcont; nlist[nlistidx++].pc = &mcont;
if (npc != &mcont) { if (npc != &mcont) {
if (matched) { if (matched) {
@@ -596,8 +608,6 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
goto _continue; goto _continue;
} else } else
npc++; npc++;
if (*nlist[nlistidx-1].pc == MATCH)
deccont()
addthread(2, nlist, nlistidx) addthread(2, nlist, nlistidx)
} }
if (sp == _sp) if (sp == _sp)