From 252cb0fe25a8cbbce19944033e311203e0fb07dc Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 1 Feb 2024 09:36:08 +1100 Subject: Add UndoAction class as internal type for undo actions and make Action a struct that is used for reporting undo steps to Document. This will allow further minimization of undo memory use. --- src/UndoHistory.cxx | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src/UndoHistory.cxx') diff --git a/src/UndoHistory.cxx b/src/UndoHistory.cxx index 6b8c65165..d667c9b4d 100644 --- a/src/UndoHistory.cxx +++ b/src/UndoHistory.cxx @@ -36,6 +36,25 @@ namespace Scintilla::Internal { +UndoAction::UndoAction() noexcept = default; + +void UndoAction::Create(ActionType at_, Sci::Position position_, const char *data_, Sci::Position lenData_, bool mayCoalesce_) { + position = position_; + at = at_; + mayCoalesce = mayCoalesce_; + lenData = lenData_; + data = nullptr; + if (lenData_) { + data = std::make_unique(lenData_); + memcpy(&data[0], data_, lenData_); + } +} + +void UndoAction::Clear() noexcept { + data = nullptr; + lenData = 0; +} + // The undo history stores a sequence of user operations that represent the user's view of the // commands executed on the text. // Each user operation contains a sequence of text insertion and text deletion actions. @@ -94,7 +113,7 @@ const char *UndoHistory::AppendAction(ActionType at, Sci::Position position, con if (0 == undoSequenceDepth) { // Top level actions may not always be coalesced ptrdiff_t targetAct = -1; - const Action *actPrevious = &(actions[currentAction + targetAct]); + const UndoAction *actPrevious = &(actions[currentAction + targetAct]); // Container actions may forward the coalesce state of Scintilla Actions. while ((actPrevious->at == ActionType::container) && actPrevious->mayCoalesce) { targetAct--; @@ -259,7 +278,7 @@ int UndoHistory::StartUndo() noexcept { return currentAction - act; } -const Action &UndoHistory::GetUndoStep() const noexcept { +const UndoAction &UndoHistory::GetUndoStep() const noexcept { return actions[currentAction]; } @@ -284,7 +303,7 @@ int UndoHistory::StartRedo() noexcept { return act - currentAction; } -const Action &UndoHistory::GetRedoStep() const noexcept { +const UndoAction &UndoHistory::GetRedoStep() const noexcept { return actions[currentAction]; } -- cgit v1.2.3