stred

Stred: Streaming Tree Editor. Like sed but for JSON
git clone http://shtanton.xyz/git/repo/stred
Log | Files | Refs | README

commit 52fff75dbe45611e05b68646dd26329411425158
parent 72964bfa1f10b183de2a1d6577aad09d81609ae3
Author: Charlie Stanton <charlie@shtanton.xyz>
Date:   Tue, 25 Apr 2023 18:33:44 +0100

Improves RunTransducer by reusing state slices for states and newStates

Diffstat:
Msubex/main.go | 5++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git 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 }