diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2023-04-21 12:51:25 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2023-04-21 12:51:25 +0100 |
commit | 26bce7119200f37f8b9f3ddc1a2c76c85f7c88be (patch) | |
tree | 21a2aa762215e2230ba676454828c1497a568cc6 /subex/main.go | |
parent | 184118c1522ee4e78a0588fcac8eb235f512b599 (diff) | |
download | stred-go-26bce7119200f37f8b9f3ddc1a2c76c85f7c88be.tar |
Changes the implementation of Atomise and Compound to no longer use goroutines
This results in a massive performance boost, ~4x speedup
Diffstat (limited to 'subex/main.go')
-rw-r--r-- | subex/main.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/subex/main.go b/subex/main.go index 9824f10..bb688e9 100644 --- a/subex/main.go +++ b/subex/main.go @@ -103,13 +103,13 @@ func pruneStates(states []SubexBranch) (newStates []SubexBranch) { } // Run the subex transducer -func RunTransducer(transducer SubexState, input <-chan walk.Atom) (output []walk.Atom, err bool) { +func RunTransducer(transducer SubexState, input []walk.Atom) (output []walk.Atom, err bool) { states := []SubexBranch{{ state: transducer, outputStack: OutputStackNil{}.push(nil), store: make(Store), }} - for piece := range input { + for _, piece := range input { var newStates []SubexBranch for _, state := range states { newStates = append(newStates, state.eat(piece)...) @@ -149,7 +149,12 @@ func Main() { close(out) }(jsonStream, tokenStream) - atoms := walk.Atomise(tokenStream) + var tokens []walk.WalkValue + for token := range tokenStream { + tokens = append(tokens, token) + } + + atoms := walk.Atomise(tokens) output, err := RunTransducer(transducer, atoms) if err { @@ -157,7 +162,7 @@ func Main() { return } - valueOut, error := walk.MemoryCompound(output) + valueOut, error := walk.Compound(output) if error != nil { fmt.Println(error.Error()) return |