From ea17251bf8be7cd09c534b39cc04e40d02e427e9 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Mon, 4 Nov 2024 08:42:26 -0500 Subject: [PATCH] Might have made a change to improve performance --- matching.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/matching.go b/matching.go index 56c6135..83f0000 100644 --- a/matching.go +++ b/matching.go @@ -169,6 +169,7 @@ func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset // i++ // } // Get the maximum index-range from the list + end := 0 if len(tempIndices) > 0 { indexToAdd := Reduce(tempIndices, func(i1 matchIndex, i2 matchIndex) matchIndex { r1 := i1.endIdx - i1.startIdx @@ -180,9 +181,14 @@ func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset }) if !overlaps(indexToAdd, indices) { 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)) copy(currentStates, tempStates)