From 687046150ab6d5fc7b0dce1392e0a60ebb6acb6f Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 1 Feb 2024 17:17:44 +1100 Subject: Change UndoHistory from an array-of-structs to a struct-of-arrays to allow each element to use minimum memory. Start by reducing (type,mayCoalesce) from 8 or 4 bytes to 1 byte. --- src/UndoHistory.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/UndoHistory.h') diff --git a/src/UndoHistory.h b/src/UndoHistory.h index 349ca2665..8975b4362 100644 --- a/src/UndoHistory.h +++ b/src/UndoHistory.h @@ -10,16 +10,21 @@ namespace Scintilla::Internal { -class UndoAction { +class UndoActionType { public: - ActionType at = ActionType::insert; - bool mayCoalesce = false; - Sci::Position position = 0; - Sci::Position lenData = 0; - - UndoAction() noexcept; - void Create(ActionType at_, Sci::Position position_=0, Sci::Position lenData_=0, bool mayCoalesce_=true) noexcept; - void Clear() noexcept; + ActionType at : 4; + bool mayCoalesce : 1; + UndoActionType() noexcept; +}; + +struct UndoActions { + std::vector types; + std::vector positions; + std::vector lengths; + + void resize(size_t length); + [[nodiscard]] size_t size() const noexcept; + void Create(size_t index, ActionType at_, Sci::Position position_ = 0, Sci::Position lenData_ = 0, bool mayCoalesce_ = true) noexcept; }; class ScrapStack { @@ -38,7 +43,7 @@ public: * */ class UndoHistory { - std::vector actions; + UndoActions actions; int maxAction = 0; int currentAction = 0; int undoSequenceDepth = 0; -- cgit v1.2.3