<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-04-25 18:33:44 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-04-25 18:33:44 +0100
commit52fff75dbe45611e05b68646dd26329411425158 (patch)
treec9722b01df4e5bdb7dbb2c39cfebdfd4ddedbbda
parent72964bfa1f10b183de2a1d6577aad09d81609ae3 (diff)
downloadstred-go-52fff75dbe45611e05b68646dd26329411425158.tar
Improves RunTransducer by reusing state slices for states and newStates
-rw-r--r--subex/main.go5
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
}