diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2023-04-25 18:33:44 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2023-04-25 18:33:44 +0100 |
commit | 52fff75dbe45611e05b68646dd26329411425158 (patch) | |
tree | c9722b01df4e5bdb7dbb2c39cfebdfd4ddedbbda | |
parent | 72964bfa1f10b183de2a1d6577aad09d81609ae3 (diff) | |
download | stred-go-52fff75dbe45611e05b68646dd26329411425158.tar |
Improves RunTransducer by reusing state slices for states and newStates
-rw-r--r-- | subex/main.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/subex/main.go b/subex/main.go index 638e0f5..ebd87cb 100644 --- a/subex/main.go +++ b/subex/main.go @@ -131,12 +131,15 @@ func RunTransducer(transducer Transducer, input []walk.Atom) (output []walk.Atom }, store: make([][]walk.Atom, transducer.storeSize), }} + var tmp []SubexBranch + newStates := make([]SubexBranch, 0, 2) for _, piece := range input { - var newStates []SubexBranch for _, state := range states { newStates = append(newStates, state.eat(piece)...) } + tmp = states states = pruneStates(newStates) + newStates = tmp[:0] if len(states) == 0 { return nil, true } |