svl/source/undo/undo.cxx |   16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

New commits:
commit 2a8506c2f20f18c948fb4dc5beb42b1010ad6999
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Nov 15 09:41:23 2021 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Nov 15 11:39:56 2021 +0100

    svl: use std::rotate() in SfxUndoManager::ImplUndo()
    
    Instead of manually moving out, moving a range and then moving in.
    
    Change-Id: Iaff461e1fcee3936c8ddc02bf471a804e7881aef
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125219
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/svl/source/undo/undo.cxx b/svl/source/undo/undo.cxx
index e820a3cbb9d1..773d17313cea 100644
--- a/svl/source/undo/undo.cxx
+++ b/svl/source/undo/undo.cxx
@@ -689,15 +689,13 @@ bool SfxUndoManager::ImplUndo( SfxUndoContext* 
i_contextOrNull )
         size_t nOffset = i_contextOrNull->GetUndoOffset();
         if (nCurrent >= nOffset + 1)
         {
-            // Move out the action we want to execute.
-            MarkedUndoAction aAction
-                = std::move(m_xData->pActUndoArray->maUndoActions[nCurrent - 1 
- nOffset]);
-            // Move the actions after aAction down by one.
-            std::move(m_xData->pActUndoArray->maUndoActions.data() + nCurrent 
- nOffset,
-                      m_xData->pActUndoArray->maUndoActions.data() + nCurrent,
-                      m_xData->pActUndoArray->maUndoActions.data() + nCurrent 
- nOffset - 1);
-            // Move aAction to the top.
-            m_xData->pActUndoArray->maUndoActions[nCurrent - 1] = 
std::move(aAction);
+            // Move the action we want to execute to the top of the undo stack.
+            // data() + nCurrent - nOffset - 1 is the start, data() + nCurrent 
- nOffset is what we
+            // want to move to the top, maUndoActions.data() + nCurrent is 
past the end/top of the
+            // undo stack.
+            std::rotate(m_xData->pActUndoArray->maUndoActions.data() + 
nCurrent - nOffset - 1,
+                        m_xData->pActUndoArray->maUndoActions.data() + 
nCurrent - nOffset,
+                        m_xData->pActUndoArray->maUndoActions.data() + 
nCurrent);
         }
     }
 

Reply via email to