From b6ab54f6dd0567c567bc162784b6711fa62c1113 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sun, 2 Feb 2025 12:42:00 -0500 Subject: [PATCH] Reset threads when findAllSubmatchHelper is called --- regex/matching.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/regex/matching.go b/regex/matching.go index a3655e9..79c38cc 100644 --- a/regex/matching.go +++ b/regex/matching.go @@ -113,7 +113,7 @@ func zeroMatchPossible(str []rune, idx int, numGroups int, states ...*nfaState) num_appended := 0 // number of unique states addded to tempstates for isZero == true { zeroStates, isZero = takeZeroState(tempstates, numGroups, idx) - tempstates, num_appended = unique_append(tempstates, zeroStates...) + tempstates, num_appended = uniqueAppend(tempstates, zeroStates...) if num_appended == 0 { // break if we haven't appended any more unique values break } @@ -258,6 +258,7 @@ func findAllSubmatchHelper(start *nfaState, str []rune, offset int, numGroups in // The second value here shouldn't be used, because we should exit when the third return value is > than len(str) return false, []Group{}, offset } + resetThreads(start) // Hold a list of match indices for the current run. When we // can no longer find a match, the match with the largest range is @@ -313,13 +314,13 @@ func findAllSubmatchHelper(start *nfaState, str []rune, offset int, numGroups in num_appended := 0 for isZero == true { zeroStates, isZero = takeZeroState(tempStates, numGroups, i) - tempStates, num_appended = unique_append(tempStates, zeroStates...) + tempStates, num_appended = uniqueAppend(tempStates, zeroStates...) if num_appended == 0 { // Break if we haven't appended any more unique values break } } - currentStates, _ = unique_append(currentStates, tempStates...) + currentStates, _ = uniqueAppend(currentStates, tempStates...) tempStates = nil // Take any transitions corresponding to current character @@ -426,7 +427,7 @@ func findAllSubmatchHelper(start *nfaState, str []rune, offset int, numGroups in num_appended := 0 // Number of unique states addded to tempStates for isZero == true { zeroStates, isZero = takeZeroState(tempStates, numGroups, i) - tempStates, num_appended = unique_append(tempStates, zeroStates...) + tempStates, num_appended = uniqueAppend(tempStates, zeroStates...) if num_appended == 0 { // Break if we haven't appended any more unique values break }