From faa55abd3d1bd239304d5b0fc4bae9d9288c1b03 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Tue, 5 Aug 2025 23:58:54 +0100 Subject: [PATCH] remove some dead code --- fcore/build-search-list.sml | 118 ------------------------------- fcore/search/search-line-gap.sml | 40 ++++++++--- 2 files changed, 32 insertions(+), 126 deletions(-) diff --git a/fcore/build-search-list.sml b/fcore/build-search-list.sml index 2378179..570594d 100644 --- a/fcore/build-search-list.sml +++ b/fcore/build-search-list.sml @@ -1,83 +1,5 @@ structure BuildSearchList = struct - fun helpNextMatch (idx, hd, tl, absIdx, searchString, matchedChrs) = - if idx = String.size hd then - case tl of - tlhd :: tltl => - helpNextMatch (0, tlhd, tltl, absIdx, searchString, matchedChrs) - | [] => NONE - else - let - val hdChr = String.sub (hd, idx) - val searchChr = String.sub (searchString, matchedChrs) - in - if hdChr = searchChr then - if matchedChrs + 1 = String.size searchString then - let val matchedIdx = absIdx - String.size searchString + 1 - in SOME matchedIdx - end - else - helpNextMatch - (idx + 1, hd, tl, absIdx + 1, searchString, matchedChrs + 1) - else - helpNextMatch (idx + 1, hd, tl, absIdx + 1, searchString, 0) - end - - fun nextMatch (bufferIdx, absIdx, rightStrings, searchString) = - case rightStrings of - hd :: tl => - let - val strIdx = Int.max (0, absIdx - bufferIdx) - in - if strIdx < String.size hd then - helpNextMatch (strIdx, hd, tl, absIdx, searchString, 0) - else - (case tl of - tlhd :: tltl => - let val strIdx = strIdx - String.size hd - in helpNextMatch (strIdx, tlhd, tltl, absIdx, searchString, 0) - end - | [] => NONE) - end - | [] => NONE - - fun helpFromStart (app, origIdx, absIdx, buffer, searchString, searchList) = - let - val buffer = LineGap.goToIdx (absIdx, buffer) - val {idx = bufferIdx, rightStrings, ...} = buffer - in - case nextMatch (bufferIdx, absIdx, rightStrings, searchString) of - SOME matchedIdx => - (* Edge case: we may be searching for a string like "a" - * when the buffer represents "aaa aaa aaa". - * In this case, there will be continual matches that are consecutive - * and we need to check every char in the buffer which is absIdx + 1. - * However, we can skip to matchedIdx + 1 if matchedIdx already exists - * in the searchList because we know the string between - * [absIdx ... matchedIdx - 1] contains no matches. - * This check is important to preserve the set-like semaantics - * of the searchList too: SearchList.append does not check for this. - * *) - if SearchList.exists (matchedIdx, searchList) then - helpFromStart - (app, origIdx, matchedIdx + 1, buffer, searchString, searchList) - else - let - val searchList = SearchList.append (matchedIdx, searchList) - in - helpFromStart - (app, origIdx, absIdx + 1, buffer, searchString, searchList) - end - | NONE => - let - val buffer = LineGap.goToIdx (origIdx, buffer) - val searchList = SearchList.goToNum (origIdx, searchList) - in - (* todo: probably change return type to (buffer * searchList) *) - AppWith.searchList (app, searchList, buffer, searchString) - end - end - fun fromStart (app, cursorIdx, buffer, searchString) = if String.size searchString > 0 then let @@ -90,46 +12,6 @@ struct else app - (* searches for matchedIdx within a range from the buffer instead of from start *) - fun helpFromRange - (origIdx, curIdx, finishIdx, buffer, searchString, searchList) = - let - val buffer = LineGap.goToIdx (curIdx, buffer) - val {idx = bufferIdx, rightStrings, ...} = buffer - in - case nextMatch (bufferIdx, curIdx, rightStrings, searchString) of - SOME matchedIdx => - if matchedIdx > finishIdx then - let - val buffer = LineGap.goToIdx (origIdx, buffer) - val searchList = SearchList.goToNum (origIdx, searchList) - in - (buffer, searchList) - end - else - let - val searchList = - if SearchList.exists (matchedIdx, searchList) then searchList - else SearchList.insert (matchedIdx, searchList) - in - helpFromRange - ( origIdx - , curIdx + 1 - , finishIdx - , buffer - , searchString - , searchList - ) - end - | NONE => - let - val buffer = LineGap.goToIdx (origIdx, buffer) - val searchList = SearchList.goToNum (origIdx, searchList) - in - (buffer, searchList) - end - end - fun fromRange (startIdx, length, buffer, searchString, searchList) = let val buffer = LineGap.goToEnd buffer diff --git a/fcore/search/search-line-gap.sml b/fcore/search/search-line-gap.sml index 4e3cc51..c817881 100644 --- a/fcore/search/search-line-gap.sml +++ b/fcore/search/search-line-gap.sml @@ -6,10 +6,8 @@ struct in case acc of hd :: tl => - if Vector.length hd < 32 then - (Vector.concat [num, hd]) :: tl - else - num :: acc + if Vector.length hd < 32 then (Vector.concat [num, hd]) :: tl + else num :: acc | [] => num :: acc end @@ -19,7 +17,8 @@ struct else if pos < 0 then case tl of hd :: tl => - searchStep (String.size hd - 1, hd, absIdx, tl, acc, searchPos, searchString) + searchStep + (String.size hd - 1, hd, absIdx, tl, acc, searchPos, searchString) | [] => acc else let @@ -27,7 +26,8 @@ struct val searchChr = String.sub (searchString, searchPos) in if bufferChr = searchChr then - searchStep (pos - 1, hd, absIdx - 1, tl, acc, searchPos - 1, searchString) + searchStep + (pos - 1, hd, absIdx - 1, tl, acc, searchPos - 1, searchString) else acc end @@ -40,7 +40,7 @@ struct | [] => acc else let - val acc = searchStep + val acc = searchStep (pos, hd, absIdx, tl, acc, String.size searchString - 1, searchString) in loopSearch (pos - 1, hd, absIdx - 1, tl, acc, searchString) @@ -58,10 +58,34 @@ struct in case leftStrings of hd :: tl => - loopSearch (String.size hd - 1, hd, absIdx - 1, tl, [], searchString) + loopSearch + (String.size hd - 1, hd, absIdx - 1, tl, [], searchString) | [] => [] end in {left = [], right = acc} end + + fun build (buffer, searchString) = + if String.size searchString > 0 then + let + val buffer = LineGap.goToEnd buffer + val searchList = search (buffer, searchString) + in + (buffer, searchList) + end + else + (buffer, SearchList.empty) + + fun buildIntoApp (app, buffer, searchString) = + if String.size searchString > 0 then + let + val buffer = LineGap.goToEnd buffer + val searchList = search (buffer, searchString) + val buffer = LineGap.goToStart buffer + in + AppWith.searchList (app, searchList, buffer, searchString) + end + else + app end