speed it up, test greediness
This commit is contained in:
61
pike.c
61
pike.c
@@ -446,8 +446,7 @@ if (si) { \
|
|||||||
|
|
||||||
#define deccheck(nn) { decref(nsub) rec_check(nn) continue; } \
|
#define deccheck(nn) { decref(nsub) rec_check(nn) continue; } \
|
||||||
|
|
||||||
#define onclist(nn)
|
#define onlist(nn) \
|
||||||
#define onnlist(nn) \
|
|
||||||
if (sdense[spc] < sparsesz) \
|
if (sdense[spc] < sparsesz) \
|
||||||
if (sdense[sdense[spc] * 2] == (unsigned int)spc) \
|
if (sdense[sdense[spc] * 2] == (unsigned int)spc) \
|
||||||
deccheck(nn) \
|
deccheck(nn) \
|
||||||
@@ -467,27 +466,21 @@ subs[si++] = nsub; \
|
|||||||
goto next##nn; \
|
goto next##nn; \
|
||||||
|
|
||||||
#define saveclist() \
|
#define saveclist() \
|
||||||
newsub(memcpy(s1->sub, nsub->sub, osubp);, \
|
if (npc[1] > nsubp / 2 && nsub->ref > 1) { \
|
||||||
memcpy(s1->sub, nsub->sub, osubp / 2);) \
|
nsub->ref--; \
|
||||||
|
newsub(memcpy(s1->sub, nsub->sub, osubp);, \
|
||||||
#define savenlist() \
|
memcpy(s1->sub, nsub->sub, osubp / 2);) \
|
||||||
newsub(/*nop*/, /*nop*/) \
|
nsub = s1; \
|
||||||
memcpy(s1->sub, nsub->sub, osubp); \
|
nsub->ref = 1; \
|
||||||
|
|
||||||
#define instclist(nn) \
|
|
||||||
else if (spc == BOL) { \
|
|
||||||
if (_sp != s) { \
|
|
||||||
if (!si && !clistidx) \
|
|
||||||
return 0; \
|
|
||||||
deccheck(nn) \
|
|
||||||
} \
|
|
||||||
npc++; goto rec##nn; \
|
|
||||||
} \
|
} \
|
||||||
|
|
||||||
#define instnlist(nn) \
|
#define savenlist() \
|
||||||
else if (spc == JMP) { \
|
if (nsub->ref > 1) { \
|
||||||
npc += 2 + npc[1]; \
|
nsub->ref--; \
|
||||||
goto rec##nn; \
|
newsub(/*nop*/, /*nop*/) \
|
||||||
|
memcpy(s1->sub, nsub->sub, osubp); \
|
||||||
|
nsub = s1; \
|
||||||
|
nsub->ref = 1; \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
#define clistmatch()
|
#define clistmatch()
|
||||||
@@ -513,17 +506,12 @@ if ((unsigned int)spc < WBEG) { \
|
|||||||
} \
|
} \
|
||||||
next##nn: \
|
next##nn: \
|
||||||
if (spc > JMP) { \
|
if (spc > JMP) { \
|
||||||
on##list(nn) \
|
onlist(nn) \
|
||||||
npc += 2; \
|
npc += 2; \
|
||||||
pcs[si] = npc + npc[-1]; \
|
pcs[si] = npc + npc[-1]; \
|
||||||
fastrec(nn, list, listidx) \
|
fastrec(nn, list, listidx) \
|
||||||
} else if (spc == SAVE) { \
|
} else if (spc == SAVE) { \
|
||||||
if (nsub->ref > 1) { \
|
save##list() \
|
||||||
nsub->ref--; \
|
|
||||||
save##list() \
|
|
||||||
nsub = s1; \
|
|
||||||
nsub->ref = 1; \
|
|
||||||
} \
|
|
||||||
nsub->sub[npc[1]] = _sp; \
|
nsub->sub[npc[1]] = _sp; \
|
||||||
npc += 2; \
|
npc += 2; \
|
||||||
goto rec##nn; \
|
goto rec##nn; \
|
||||||
@@ -534,7 +522,7 @@ if (spc > JMP) { \
|
|||||||
npc++; goto rec##nn; \
|
npc++; goto rec##nn; \
|
||||||
} else if (spc < 0) { \
|
} else if (spc < 0) { \
|
||||||
spc = -spc; \
|
spc = -spc; \
|
||||||
on##list(nn) \
|
onlist(nn) \
|
||||||
npc += 2; \
|
npc += 2; \
|
||||||
pcs[si] = npc; \
|
pcs[si] = npc; \
|
||||||
npc += npc[-1]; \
|
npc += npc[-1]; \
|
||||||
@@ -547,8 +535,17 @@ if (spc > JMP) { \
|
|||||||
if (*_sp) \
|
if (*_sp) \
|
||||||
deccheck(nn) \
|
deccheck(nn) \
|
||||||
npc++; goto rec##nn; \
|
npc++; goto rec##nn; \
|
||||||
} inst##list(nn) \
|
} else if (spc == JMP) { \
|
||||||
deccheck(nn) \
|
npc += 2 + npc[1]; \
|
||||||
|
goto rec##nn; \
|
||||||
|
} else { \
|
||||||
|
if (_sp != s) { \
|
||||||
|
if (!si && !clistidx) \
|
||||||
|
return 0; \
|
||||||
|
deccheck(nn) \
|
||||||
|
} \
|
||||||
|
npc++; goto rec##nn; \
|
||||||
|
} \
|
||||||
|
|
||||||
#define swaplist() \
|
#define swaplist() \
|
||||||
tmp = clist; \
|
tmp = clist; \
|
||||||
@@ -567,7 +564,7 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
|
|||||||
int *insts = prog->insts;
|
int *insts = prog->insts;
|
||||||
int *pcs[prog->splits];
|
int *pcs[prog->splits];
|
||||||
rsub *subs[prog->splits];
|
rsub *subs[prog->splits];
|
||||||
unsigned int sdense[prog->sparsesz], sparsesz;
|
unsigned int sdense[prog->sparsesz], sparsesz = 0;
|
||||||
rsub *nsub, *s1, *matched = NULL, *freesub = NULL;
|
rsub *nsub, *s1, *matched = NULL, *freesub = NULL;
|
||||||
rthread _clist[prog->len], _nlist[prog->len];
|
rthread _clist[prog->len], _nlist[prog->len];
|
||||||
rthread *clist = _clist, *nlist = _nlist, *tmp;
|
rthread *clist = _clist, *nlist = _nlist, *tmp;
|
||||||
|
|||||||
39
test.sh
39
test.sh
@@ -172,6 +172,19 @@ aaaaa(aa)aa(aa(a)a)?aa
|
|||||||
([0-9])+.(.*)
|
([0-9])+.(.*)
|
||||||
(([0-9])+)(.)(.*)
|
(([0-9])+)(.)(.*)
|
||||||
(abc|sjd|qwq(hs|qw|oo)|(ty|xx|pp)we)
|
(abc|sjd|qwq(hs|qw|oo)|(ty|xx|pp)we)
|
||||||
|
(a?)?
|
||||||
|
(a?)?
|
||||||
|
(a?)??
|
||||||
|
(a?)(a?)(a?a?)aaa(a?)|(b?)
|
||||||
|
(a?)(a?)(a?a?)aaa(a?)|(b?)
|
||||||
|
(a*)??
|
||||||
|
(a*)|(b*)|(c*)
|
||||||
|
(a?|a?)|(a*)?
|
||||||
|
(a?|a?)a|(a*)?
|
||||||
|
(a?|a?)d|(a*)?
|
||||||
|
((a*b*c*)|(a*c*b*))+?
|
||||||
|
((a*b*c*)|(a*c*b*))*?
|
||||||
|
((a*b*c*)|(a*c*b*))+
|
||||||
"
|
"
|
||||||
input="\
|
input="\
|
||||||
abcdef
|
abcdef
|
||||||
@@ -345,6 +358,19 @@ h:98: :3234utt;strokeliin:miter;stroke-mirlimit:10;stroke-dasharray:none;strok
|
|||||||
650-253-000123434-45551221
|
650-253-000123434-45551221
|
||||||
650-253-000123434-455512213224hsaqer
|
650-253-000123434-455512213224hsaqer
|
||||||
ppwe
|
ppwe
|
||||||
|
m
|
||||||
|
a
|
||||||
|
aa
|
||||||
|
aa
|
||||||
|
aaaaaaaaaaaaaa
|
||||||
|
a
|
||||||
|
bbbbbbbbb
|
||||||
|
aaa
|
||||||
|
aaa
|
||||||
|
aaa
|
||||||
|
bbb
|
||||||
|
bbb
|
||||||
|
bbb
|
||||||
"
|
"
|
||||||
expect="\
|
expect="\
|
||||||
(0,3)
|
(0,3)
|
||||||
@@ -518,6 +544,19 @@ expect="\
|
|||||||
(0,26)(2,3)(4,26)
|
(0,26)(2,3)(4,26)
|
||||||
(0,36)(0,3)(2,3)(3,4)(4,36)
|
(0,36)(0,3)(2,3)(3,4)(4,36)
|
||||||
(0,4)(0,4)(?,?)(0,2)
|
(0,4)(0,4)(?,?)(0,2)
|
||||||
|
(0,0)(0,0)
|
||||||
|
(0,1)(0,1)
|
||||||
|
(0,0)(?,?)
|
||||||
|
(0,0)(?,?)(?,?)(?,?)(?,?)(0,0)
|
||||||
|
(0,8)(0,1)(1,2)(2,4)(7,8)(?,?)
|
||||||
|
(0,0)(?,?)
|
||||||
|
(0,0)(0,0)(?,?)(?,?)
|
||||||
|
(0,1)(0,1)(?,?)
|
||||||
|
(0,2)(0,1)(?,?)
|
||||||
|
(0,3)(?,?)(0,3)
|
||||||
|
(0,3)(0,3)(0,3)(?,?)
|
||||||
|
(0,0)(?,?)(?,?)(?,?)
|
||||||
|
(0,3)(0,3)(0,3)(?,?)
|
||||||
(0,0)
|
(0,0)
|
||||||
"
|
"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user