diff options
author | Ori Bernstein <ori@eigenstate.org> | 2017-12-27 21:03:13 -0800 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2017-12-27 21:03:13 -0800 |
commit | a434ff7d4dfa4121e1070bbba0754bbbd04630c4 (patch) | |
tree | a2a48831b4fbee09f48467e764fa9ef0002f3235 | |
parent | 3ca7a098ddb3aacabafb6c20a57feec1dbafe4ab (diff) | |
download | mc-a434ff7d4dfa4121e1070bbba0754bbbd04630c4.tar.gz |
Speed up regex.
Double performance.
-rw-r--r-- | lib/regex/interp.myr | 36 | ||||
-rw-r--r-- | lib/regex/types.myr | 3 |
2 files changed, 17 insertions, 22 deletions
diff --git a/lib/regex/interp.myr b/lib/regex/interp.myr index 0bc47e6..ee12369 100644 --- a/lib/regex/interp.myr +++ b/lib/regex/interp.myr @@ -235,7 +235,6 @@ const run = {re, str, idx, wholestr re.traces = [][:] std.slpush(&re.traces, std.mkbs()) ;; - re.runq.mgroup = std.slalloc(re.nmatch) for var i = 0; i < re.nmatch; i++ re.runq.mgroup[i][0] = -1 re.runq.mgroup[i][1] = -1 @@ -306,7 +305,7 @@ const run = {re, str, idx, wholestr */ const step = {re, thr, curip var str - var mgroup + var nthr str = re.str match re.prog[thr.ip] @@ -377,7 +376,6 @@ const step = {re, thr, curip ;; | `Ilbra m: trace(re, thr, "\t{}:\tLbra {}\n", thr.ip, m) - trace(re, thr, "\t\tmatch start = {}\n", re.strp) thr.mgroup[m][0] = re.strp hit(re, thr) thr.ip++ @@ -390,9 +388,13 @@ const step = {re, thr, curip -> false | `Ifork (lip, rip): trace(re, thr, "\t{}:\tFork ({}, {})\n", thr.ip, lip, rip) - mgroup = std.sldup(thr.mgroup) hit(re, thr) - fork(re, rip, curip, mgroup) + if rip != curip + nthr = mkthread(re, rip) + nthr.next = re.runq + nthr.mgroup = thr.mgroup + re.runq = nthr + ;; if re.debug std.slpush(&re.traces, std.bsdup(re.traces[thr.tid])) ;; @@ -412,18 +414,6 @@ const step = {re, thr, curip -> true } -const fork = {re, ip, curip, mgroup - var thr - - if ip == curip /* loop detection */ - -> void - ;; - thr = mkthread(re, ip) - thr.next = re.runq - thr.mgroup = mgroup - re.runq = thr -} - const die = {re, thr, msg /* we can have die called on a thread @@ -450,21 +440,25 @@ const finish = {re, thr const mkthread = {re, ip var thr : rethread# - thr = std.alloc() + if re.freed != Zthr + thr = re.freed + re.freed = thr.next + else + thr = std.alloc() + ;; thr.next = Zthr thr.ip = ip thr.tid = re.nexttid++ thr.dead = false thr.matched = false - thr.mgroup = [][:] re.nthr++ -> thr } const thrfree = {re, thr - std.slfree(thr.mgroup) - std.free(thr) + thr.next = re.freed + re.freed = thr } const within = {re, str diff --git a/lib/regex/types.myr b/lib/regex/types.myr index c21d474..d06cfe1 100644 --- a/lib/regex/types.myr +++ b/lib/regex/types.myr @@ -23,6 +23,7 @@ pkg regex = runq : rethread# expired : rethread# expiredtail : rethread# + freed : rethread# proglen : std.size prog : reinst[:] nthr : std.size @@ -68,7 +69,7 @@ pkg regex = dead : bool /* thread died */ matched : bool /* thread matched */ - mgroup : std.size[2][:] /* match starts */ + mgroup : std.size[2][32] /* match starts */ ;; pkglocal type reinst = union |