when deleting from buffer and search list both, don't try to find any matches if the DFA is empty (has a length of 0), because that means there is no search to find a match for

This commit is contained in:
2026-02-06 21:25:44 +00:00
parent 2292c30cd3
commit b02b2f53da

View File

@@ -146,15 +146,7 @@ struct
end
else if PersistentVector.isInRange (idx, searchList) then
(buffer, searchList)
else
let
val buffer = LineGap.goToIdx (idx, buffer)
val chr = LineGap.sub (idx, buffer)
val newState = Dfa.nextState (dfa, curState, chr)
val prevFinalPos =
if Dfa.isFinal (dfa, newState) then idx else prevFinalPos
in
if Dfa.isDead newState then
else if Dfa.isDead curState then
if prevFinalPos = ~1 then
(* no match found: restart search from `startPos + 1` *)
insertUntilMatch
@@ -167,10 +159,16 @@ struct
(startPos, prevFinalPos, searchList)
val newStart = prevFinalPos + 1
in
insertUntilMatch
(newStart, buffer, searchList, dfa, 0, newStart, ~1)
insertUntilMatch (newStart, buffer, searchList, dfa, 0, newStart, ~1)
end
else
let
val buffer = LineGap.goToIdx (idx, buffer)
val chr = LineGap.sub (idx, buffer)
val newState = Dfa.nextState (dfa, curState, chr)
val prevFinalPos =
if Dfa.isFinal (dfa, newState) then idx else prevFinalPos
in
(* continue *)
insertUntilMatch
(idx + 1, buffer, searchList, dfa, newState, startPos, prevFinalPos)
@@ -223,6 +221,9 @@ struct
PersistentVector.helpPrevMatch (start, searchList, 0)
val searchStart = searchStart + 1
in
if Vector.length dfa = 0 then
(buffer, searchList)
else
insertUntilMatch
(searchStart, buffer, searchList, dfa, 0, searchStart, ~1)
end