diff options
Diffstat (limited to 'subex')
-rw-r--r-- | subex/main.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/subex/main.go b/subex/main.go index 635b1de..638e0f5 100644 --- a/subex/main.go +++ b/subex/main.go @@ -107,16 +107,18 @@ func equalStates(left SubexBranch, right SubexBranch) bool { // If two branches have the same state, only the first has a chance of being successful // This function removes all of the pointless execution branches to save execution time -func pruneStates(states []SubexBranch) (newStates []SubexBranch) { +func pruneStates(states []SubexBranch) []SubexBranch { + uniqueStates := 0 outer: for _, state := range states { - for _, newState := range newStates { - if equalStates(state, newState) { + for i := 0; i < uniqueStates; i++ { + if equalStates(state, states[i]) { continue outer } } - newStates = append(newStates, state) + states[uniqueStates] = state + uniqueStates++ } - return newStates + return states[:uniqueStates] } // Run the subex transducer |