From 52fff75dbe45611e05b68646dd26329411425158 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Tue, 25 Apr 2023 18:33:44 +0100 Subject: Improves RunTransducer by reusing state slices for states and newStates --- subex/main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'subex/main.go') 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 } -- cgit v1.2.3