Might have made a change to improve performance

master
Aadhavan Srinivasan 2 months ago
parent e8aca8606a
commit ea17251bf8

@ -169,6 +169,7 @@ func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset
// i++ // i++
// } // }
// Get the maximum index-range from the list // Get the maximum index-range from the list
end := 0
if len(tempIndices) > 0 { if len(tempIndices) > 0 {
indexToAdd := Reduce(tempIndices, func(i1 matchIndex, i2 matchIndex) matchIndex { indexToAdd := Reduce(tempIndices, func(i1 matchIndex, i2 matchIndex) matchIndex {
r1 := i1.endIdx - i1.startIdx r1 := i1.endIdx - i1.startIdx
@ -180,9 +181,14 @@ func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset
}) })
if !overlaps(indexToAdd, indices) { if !overlaps(indexToAdd, indices) {
indices, _ = unique_append(indices, indexToAdd) indices, _ = unique_append(indices, indexToAdd)
end = indexToAdd.endIdx
} }
} }
return findAllMatchesHelper(start, str, indices, startIdx) if end == 0 || end == startIdx-1 { // Since we incremented startIdx earlier, we need to check against the old startIdx
return findAllMatchesHelper(start, str, indices, startIdx)
} else {
return findAllMatchesHelper(start, str, indices, end)
}
} }
currentStates = make([]*State, len(tempStates)) currentStates = make([]*State, len(tempStates))
copy(currentStates, tempStates) copy(currentStates, tempStates)

Loading…
Cancel
Save