reduce unnecessary intermediary allocations in app-update.sml's 'helpDeleteToChr' function, similarly to previous commit

This commit is contained in:
2024-11-09 09:59:12 +00:00
parent 5804620846
commit cde4dbc67f
2 changed files with 11 additions and 9 deletions

View File

@@ -428,25 +428,27 @@ struct
buildTextAndClear (app, buffer, low) buildTextAndClear (app, buffer, low)
end end
fun helpDeleteToChr (app: app_type, buffer, cursorIdx, count, fMove, fInc, chr) = fun helpDeleteToChr (app: app_type, buffer, cursorIdx, otherIdx, count, fMove, fInc, chr) =
if count = 0 then if count = 0 then
buildTextAndClearAfterChr (app, buffer, cursorIdx)
else
let let
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val otherIdx = fInc (fMove (buffer, cursorIdx, chr), 1)
val low = Int.min (cursorIdx, otherIdx) val low = Int.min (cursorIdx, otherIdx)
val high = Int.max (cursorIdx, otherIdx) val high = Int.max (cursorIdx, otherIdx)
val length = high - low val length = high - low
val buffer = LineGap.delete (low, length, buffer) val buffer = LineGap.delete (low, length, buffer)
in in
helpDeleteToChr (app, buffer, low, count - 1, fMove, fInc, chr) buildTextAndClearAfterChr (app, buffer, low)
end
else
let
val buffer = LineGap.goToIdx (otherIdx, buffer)
val otherIdx = fInc (fMove (buffer, otherIdx, chr), 1)
in
helpDeleteToChr (app, buffer, cursorIdx, otherIdx, count - 1, fMove, fInc, chr)
end end
fun deleteToChr (app: app_type, count, fMove, fInc, chr) = fun deleteToChr (app: app_type, count, fMove, fInc, chr) =
helpDeleteToChr (app, #buffer app, #cursorIdx app, count, fMove, fInc, chr) helpDeleteToChr
(app, #buffer app, #cursorIdx app, #cursorIdx app, count, fMove, fInc, chr)
(* command-parsing functions *) (* command-parsing functions *)
(** number of characters which are integers *) (** number of characters which are integers *)

BIN
shf

Binary file not shown.