ref: 581412fba531601c7232bfff0e371c7471ca2c04
parent: 872cef584db8fdb766f03e7cc5df8e6ea5c7ebdc
author: Tor Andersson <tor@ccxvii.net>
date: Thu Mar 30 09:00:35 EDT 2017
Optimize regexp interpreter loop. Only jump once after each instruction.
--- a/regexp.c
+++ b/regexp.c
@@ -1026,7 +1026,8 @@
sp += chartorune(&c, sp);
if (c == 0)
goto dead;
- break;
+ pc = pc + 1;
+ continue;
case I_ANY:
sp += chartorune(&c, sp);
if (c == 0)
@@ -1033,7 +1034,8 @@
goto dead;
if (isnewline(c))
goto dead;
- break;
+ pc = pc + 1;
+ continue;
case I_CHAR:
sp += chartorune(&c, sp);
if (c == 0)
@@ -1042,7 +1044,8 @@
c = canon(c);
if (c != pc->c)
goto dead;
- break;
+ pc = pc + 1;
+ continue;
case I_CCLASS:
sp += chartorune(&c, sp);
if (c == 0)
@@ -1054,7 +1057,8 @@
if (!incclass(pc->cc, c))
goto dead;
}
- break;
+ pc = pc + 1;
+ continue;
case I_NCCLASS:
sp += chartorune(&c, sp);
if (c == 0)
@@ -1066,7 +1070,8 @@
if (incclass(pc->cc, c))
goto dead;
}
- break;
+ pc = pc + 1;
+ continue;
case I_REF:
i = sub.sub[pc->n].ep - sub.sub[pc->n].sp;
if (flags & REG_ICASE) {
@@ -1078,45 +1083,59 @@
}
if (i > 0)
sp += i;
- break;
+ pc = pc + 1;
+ continue;
case I_BOL:
- if (sp == bol && !(flags & REG_NOTBOL))
- break;
- if (flags & REG_NEWLINE)
- if (sp > bol && isnewline(sp[-1]))
- break;
+ if (sp == bol && !(flags & REG_NOTBOL)) {
+ pc = pc + 1;
+ continue;
+ }
+ if (flags & REG_NEWLINE) {
+ if (sp > bol && isnewline(sp[-1])) {
+ pc = pc + 1;
+ continue;
+ }
+ }
goto dead;
case I_EOL:
- if (*sp == 0)
- break;
- if (flags & REG_NEWLINE)
- if (isnewline(*sp))
- break;
+ if (*sp == 0) {
+ pc = pc + 1;
+ continue;
+ }
+ if (flags & REG_NEWLINE) {
+ if (isnewline(*sp)) {
+ pc = pc + 1;
+ continue;
+ }
+ }
goto dead;
case I_WORD:
i = sp > bol && iswordchar(sp[-1]);
i ^= iswordchar(sp[0]);
- if (i)
- break;
- goto dead;
+ if (!i)
+ goto dead;
+ pc = pc + 1;
+ continue;
case I_NWORD:
i = sp > bol && iswordchar(sp[-1]);
i ^= iswordchar(sp[0]);
- if (!i)
- break;
- goto dead;
+ if (i)
+ goto dead;
+ pc = pc + 1;
+ continue;
case I_LPAR:
sub.sub[pc->n].sp = sp;
- break;
+ pc = pc + 1;
+ continue;
case I_RPAR:
sub.sub[pc->n].ep = sp;
- break;
+ pc = pc + 1;
+ continue;
default:
goto dead;
}
- pc = pc + 1;
}
dead: ;
}