pass DFA to 'SearchList.buildRange' function, so that we don't need to parse search string into DFA each time

This commit is contained in:
2025-10-08 05:20:33 +01:00
parent fd8385fa81
commit 8857f49537
5 changed files with 75 additions and 54 deletions

View File

@@ -18,7 +18,7 @@ struct
val buffer = LineGap.goToIdx (low - 1111, buffer) val buffer = LineGap.goToIdx (low - 1111, buffer)
val (buffer, searchList) = val (buffer, searchList) =
SearchList.buildRange (buffer, searchString, low + 1111) SearchList.buildRange (buffer, searchString, low + 1111, #dfa app)
val buffer = LineGap.goToIdx (low, buffer) val buffer = LineGap.goToIdx (low, buffer)
in in
@@ -241,7 +241,8 @@ struct
val buffer = LineGap.goToIdx (cursorIdx - 1111, buffer) val buffer = LineGap.goToIdx (cursorIdx - 1111, buffer)
val (buffer, searchList) = val (buffer, searchList) =
SearchList.buildRange (buffer, searchString, cursorIdx + 1111) SearchList.buildRange
(buffer, searchString, cursorIdx + 1111, #dfa app)
(* If we have deleted from the buffer so that cursorIdx (* If we have deleted from the buffer so that cursorIdx
* is no longer a valid idx, * is no longer a valid idx,
@@ -705,7 +706,7 @@ struct
fun deleteToStart (app: app_type, time) : AppType.app_type = fun deleteToStart (app: app_type, time) : AppType.app_type =
let let
val {cursorIdx, buffer, windowWidth, windowHeight, searchString, ...} = val {cursorIdx, buffer, windowWidth, windowHeight, searchString, dfa, ...} =
app app
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
val cursorIdx = Cursor.viDlrForDelete (buffer, cursorIdx, 1) val cursorIdx = Cursor.viDlrForDelete (buffer, cursorIdx, 1)
@@ -719,7 +720,7 @@ struct
val buffer = LineGap.goToIdx (cursorIdx - 1111, buffer) val buffer = LineGap.goToIdx (cursorIdx - 1111, buffer)
val (buffer, searchList) = val (buffer, searchList) =
SearchList.buildRange (buffer, searchString, cursorIdx + 1111) SearchList.buildRange (buffer, searchString, cursorIdx + 1111, dfa)
val cursorIdx = 0 val cursorIdx = 0
val startLine = 0 val startLine = 0
@@ -756,7 +757,7 @@ struct
fun helpDeleteToMatch (app: app_type, low, high, time) = fun helpDeleteToMatch (app: app_type, low, high, time) =
let let
val {buffer, searchString, ...} = app val {buffer, searchString, dfa, ...} = app
val buffer = LineGap.goToIdx (high, buffer) val buffer = LineGap.goToIdx (high, buffer)
val length = high - low val length = high - low
val initialMsg = Fn.initMsgs (low, length, buffer) val initialMsg = Fn.initMsgs (low, length, buffer)
@@ -767,7 +768,7 @@ struct
val buffer = LineGap.goToIdx (low - 1111, buffer) val buffer = LineGap.goToIdx (low - 1111, buffer)
val (buffer, searchList) = val (buffer, searchList) =
SearchList.buildRange (buffer, searchString, low + 1111) SearchList.buildRange (buffer, searchString, low + 1111, dfa)
val buffer = LineGap.goToIdx (low, buffer) val buffer = LineGap.goToIdx (low, buffer)
in in
@@ -804,7 +805,7 @@ struct
fun deleteInsideWord (app: app_type, time) = fun deleteInsideWord (app: app_type, time) =
let let
val {buffer, cursorIdx, searchString, ...} = app val {buffer, cursorIdx, searchString, dfa, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
val low = Cursor.prevWordStrict (buffer, cursorIdx, 1) val low = Cursor.prevWordStrict (buffer, cursorIdx, 1)
@@ -826,7 +827,7 @@ struct
val buffer = LineGap.goToIdx (low - 1111, buffer) val buffer = LineGap.goToIdx (low - 1111, buffer)
val (buffer, searchList) = val (buffer, searchList) =
SearchList.buildRange (buffer, searchString, low + 1111) SearchList.buildRange (buffer, searchString, low + 1111, dfa)
val buffer = LineGap.goToIdx (low, buffer) val buffer = LineGap.goToIdx (low, buffer)
in in
@@ -839,7 +840,7 @@ struct
fun deleteInsideWORD (app: app_type, time) = fun deleteInsideWORD (app: app_type, time) =
let let
val {buffer, cursorIdx, searchString, ...} = app val {buffer, cursorIdx, searchString, dfa, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
val low = Cursor.prevWORDStrict (buffer, cursorIdx, 1) val low = Cursor.prevWORDStrict (buffer, cursorIdx, 1)
@@ -858,7 +859,7 @@ struct
val buffer = LineGap.goToIdx (low - 1111, buffer) val buffer = LineGap.goToIdx (low - 1111, buffer)
val (buffer, searchList) = val (buffer, searchList) =
SearchList.buildRange (buffer, searchString, low + 1111) SearchList.buildRange (buffer, searchString, low + 1111, dfa)
val buffer = LineGap.goToIdx (low, buffer) val buffer = LineGap.goToIdx (low, buffer)
in in
@@ -874,7 +875,7 @@ struct
NormalFinish.clearMode app NormalFinish.clearMode app
else else
let let
val {cursorIdx, buffer, searchString, ...} = app val {cursorIdx, buffer, searchString, dfa, ...} = app
val low = origLow + 1 val low = origLow + 1
val length = high - low val length = high - low
@@ -887,7 +888,7 @@ struct
val buffer = LineGap.goToIdx (low - 1111, buffer) val buffer = LineGap.goToIdx (low - 1111, buffer)
val (buffer, searchList) = val (buffer, searchList) =
SearchList.buildRange (buffer, searchString, low + 1111) SearchList.buildRange (buffer, searchString, low + 1111, dfa)
val buffer = LineGap.goToIdx (origLow, buffer) val buffer = LineGap.goToIdx (origLow, buffer)
in in
@@ -970,7 +971,7 @@ struct
fun deletePair (app: app_type, time) = fun deletePair (app: app_type, time) =
let let
val {cursorIdx, buffer, ...} = app val {cursorIdx, buffer, dfa, ...} = app
val otherIdx = Cursor.matchPair (buffer, cursorIdx) val otherIdx = Cursor.matchPair (buffer, cursorIdx)
in in
if otherIdx = cursorIdx then if otherIdx = cursorIdx then
@@ -1001,7 +1002,7 @@ struct
val buffer = LineGap.goToIdx (low - 1111, buffer) val buffer = LineGap.goToIdx (low - 1111, buffer)
val (buffer, searchList) = val (buffer, searchList) =
SearchList.buildRange (buffer, searchString, low + 1111) SearchList.buildRange (buffer, searchString, low + 1111, dfa)
val buffer = LineGap.goToIdx (low, buffer) val buffer = LineGap.goToIdx (low, buffer)
in in

View File

@@ -49,6 +49,7 @@ struct
, floatWindowHeight , floatWindowHeight
, searchCursorIdx , searchCursorIdx
, searchScrollColumn , searchScrollColumn
, caseSensitive
) )
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
@@ -121,6 +122,7 @@ struct
, floatWindowHeight , floatWindowHeight
, searchCursorIdx , searchCursorIdx
, searchScrollColumn , searchScrollColumn
, caseSensitive
) )
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)

View File

@@ -4,8 +4,14 @@ struct
open InputMsg open InputMsg
open MailboxType open MailboxType
fun buildTempSearchList (searchString, buffer, cursorIdx) = fun buildTempSearchList (searchString, buffer, cursorIdx, caseSensitive) =
SearchList.buildRange (buffer, searchString, cursorIdx + 1111) let
val dfa =
if caseSensitive then CaseSensitiveDfa.fromString searchString
else CaseInsensitiveDfa.fromString searchString
in
SearchList.buildRange (buffer, searchString, cursorIdx + 1111, dfa)
end
fun addChr fun addChr
( app: app_type ( app: app_type
@@ -34,7 +40,7 @@ struct
val buffer = LineGap.goToIdx (cursorIdx - 1111, buffer) val buffer = LineGap.goToIdx (cursorIdx - 1111, buffer)
val (buffer, tempSearchList) = val (buffer, tempSearchList) =
buildTempSearchList (searchString, buffer, cursorIdx) buildTempSearchList (searchString, buffer, cursorIdx, caseSensitive)
in in
NormalSearchFinish.onSearchChanged NormalSearchFinish.onSearchChanged
( app ( app
@@ -58,7 +64,8 @@ struct
end end
(* save search string and tempSearchList and return to normal mode *) (* save search string and tempSearchList and return to normal mode *)
fun saveSearch (app: app_type, searchString, tempSearchList, time) = fun saveSearch
(app: app_type, searchString, tempSearchList, caseSensitive, time) =
let let
val val
{ buffer { buffer
@@ -94,7 +101,9 @@ struct
val mode = NORMAL_MODE "" val mode = NORMAL_MODE ""
val dfa = raise Fail "todo" val dfa =
if caseSensitive then CaseSensitiveDfa.fromString searchString
else CaseInsensitiveDfa.fromString searchString
in in
NormalSearchModeWith.returnToNormalMode NormalSearchModeWith.returnToNormalMode
(app, buffer, searchString, tempSearchList, startLine, mode, dfa, msgs) (app, buffer, searchString, tempSearchList, startLine, mode, dfa, msgs)
@@ -129,7 +138,7 @@ struct
val {cursorIdx, buffer, ...} = app val {cursorIdx, buffer, ...} = app
val buffer = LineGap.goToIdx (cursorIdx - 1111, buffer) val buffer = LineGap.goToIdx (cursorIdx - 1111, buffer)
val (buffer, tempSearchList) = val (buffer, tempSearchList) =
buildTempSearchList (searchString, buffer, cursorIdx) buildTempSearchList (searchString, buffer, cursorIdx, caseSensitive)
in in
NormalSearchFinish.onSearchChanged NormalSearchFinish.onSearchChanged
( app ( app
@@ -224,7 +233,8 @@ struct
, caseSensitive , caseSensitive
) )
| KEY_ESC => exitToNormalMode app | KEY_ESC => exitToNormalMode app
| KEY_ENTER => saveSearch (app, searchString, tempSearchList, time) | KEY_ENTER =>
saveSearch (app, searchString, tempSearchList, caseSensitive, time)
| ARROW_LEFT => | ARROW_LEFT =>
moveLeft moveLeft
( app ( app

View File

@@ -159,14 +159,8 @@ struct
) )
end end
fun buildRange (buffer, searchString, finishIdx) = fun buildRange (buffer, searchString, finishIdx, dfa) =
if String.size searchString > 0 then if String.size searchString > 0 andalso Vector.length dfa > 0 then
let
val dfa = DfaGen.fromString searchString
in
if Vector.length dfa = 0 then
(buffer, PersistentVector.empty)
else
rangeLoop rangeLoop
( dfa ( dfa
, #idx buffer , #idx buffer
@@ -177,7 +171,6 @@ struct
, #idx buffer , #idx buffer
, ~1 , ~1
) )
end
else else
(buffer, PersistentVector.empty) (buffer, PersistentVector.empty)

View File

@@ -59,11 +59,12 @@ struct
, floatWindowHeight , floatWindowHeight
, searchCursorIdx , searchCursorIdx
, searchScrollColumn , searchScrollColumn
, caseSensitive
) = ) =
let let
val r: Real32.real = 0.67 val r: Real32.real = 0.1
val g: Real32.real = 0.51 val g: Real32.real = 0.1
val b: Real32.real = 0.83 val b: Real32.real = 0.1
val z: Real32.real = 0.1 val z: Real32.real = 0.1
val width = endX - startX val width = endX - startX
@@ -101,11 +102,25 @@ struct
val xpos = Int.min (endX, xpos) val xpos = Int.min (endX, xpos)
val x = Real32.fromInt xpos val x = Real32.fromInt xpos
in in
if caseSensitive then
CozetteAscii.make
( #"?"
, x
, fPosY
, 0.01
, TC.scale
, floatWindowWidth
, floatWindowWidth
, r
, g
, b
)
else
PipeCursor.lerp PipeCursor.lerp
( x ( x
, fPosY , fPosY
, 0.01 , 0.01
, TextConstants.scale , TC.scale
, floatWindowWidth , floatWindowWidth
, floatWindowHeight , floatWindowHeight
, r , r