diff options
| author | Drahflow <drahflow@gmx.de> | 2017-02-12 23:46:52 +0100 |
|---|---|---|
| committer | Drahflow <drahflow@gmx.de> | 2017-02-12 23:46:52 +0100 |
| commit | 818b3e2105deaff43ac2371491b73070be437d4c (patch) | |
| tree | 692081dc8db09c8b5b771f5e7db97a35826946b1 | |
| parent | 55a5e390844e3344a7031efb13083d1920971ca0 (diff) | |
Some speed boost on typical regex usage
| -rw-r--r-- | compiler/standardClient.ey | 78 |
1 files changed, 57 insertions, 21 deletions
diff --git a/compiler/standardClient.ey b/compiler/standardClient.ey index 3b7828f..d807d7c 100644 --- a/compiler/standardClient.ey +++ b/compiler/standardClient.ey @@ -8,6 +8,7 @@ # ideas taken from http://swtch.com/~rsc/regexp/regexp3.html < 0 ==:MATCH 1 ==:TERM 2 ==:JUMP 3 ==:SPLIT 4 ==:SAVE 5 ==:FIRST 6 ==:LAST + 7 ==:FLOATBEGIN 8 ==:TERMBEGIN { ==b ==a [ [ SPLIT 1 a len 2 add ] @@ -267,27 +268,36 @@ { [ 0 # pc [ currentCapture { 0 0 } rep ] # captures - ] } /newThread deff + ] }" /newThread deff # TODO: reconsider clist/ilist and also reconsider optimisation potential - { ==prog ==string + { ==string 0 ==position string len ==maxPosition 0 ==matched - < > ==matchedThread + [ ] ==matchedThread - prog len _ threadList ==clist - _ threadList ==nlist - threadList ==ilist + clist .clear + nlist .clear + ilist .clear newThread _ ==thread clist .add 0 ==pc - { } =*code + [ ] =*code ilist .|add =*iPush ilist .|pop =*iPop + { + { ilist .size }" { + iPop _ =thread + threadGetPC _ =pc + prog * =code + 0 code codeSemantics * + }" loop + }" /runIList deffst + [ { # MATCH 1 =matched @@ -310,6 +320,27 @@ position 0 eq { pc 1 add thread cloneThread iPush }" rep }" { # LAST position maxPosition eq { pc 1 add thread cloneThread iPush }" rep + }" { # FLOATBEGIN + pc 1 add thread cloneThread iPush + thread + runIList + position maxPosition lt { + nlist .add + }" { -- }" ? * + }" { # TERMBEGIN + 1 code =*p + nlist .size not clist .size 1 eq and { + { position maxPosition lt { position string * p not }" { 0 }" ? * }" { + position 1 add =position + }" loop + }" rep + + position maxPosition lt { + position string * p { + pc 1 add thread cloneThread nlist .add + }" rep + thread nlist .add + }" rep }" ] =*codeSemantics @@ -324,12 +355,7 @@ 0 code codeSemantics * i 1 add =i - { ilist .size }" { - iPop _ =thread - threadGetPC _ =pc - prog * =code - 0 code codeSemantics * - }" loop + runIList }" loop # "Next input character ========" dump @@ -348,7 +374,7 @@ } loop } rep matched - } /execute deffst + }' /execute defvst parse ==prog -- prog 0 -01 * 0 -01 * FIRST eq { @@ -356,18 +382,28 @@ 1 prog len range { prog * } each ] =prog } { - [ - [ SPLIT 3 1 ] - [ TERM { -- 1 }" ] - [ JUMP 2 neg ] - prog _ len dearray - ] =prog + prog 0 -01 * 0 -01 * TERM eq { + [ + [ TERMBEGIN 1 0 prog * * ] + 1 prog len range { prog * } each + ] =prog + } { + [ + [ FLOATBEGIN ] + prog _ len dearray + ] =prog + } ? * } ? * [ prog _ len dearray [ MATCH ] ] =prog - { prog execute } + + prog len _ threadList ==clist + _ threadList ==nlist + threadList ==ilist + + execute } > -- /enregex deffd |
