sw/inc/undobj.hxx              |    4 ++--
 sw/source/core/undo/untblk.cxx |   23 +++++++++++------------
 2 files changed, 13 insertions(+), 14 deletions(-)

New commits:
commit 032bacd44fc1a4a9c55139aa3fc13d988ef3d6a9
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Mon Aug 8 14:01:24 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Aug 10 08:08:05 2022 +0200

    unique_ptr->optional in SwUndoInserts
    
    Change-Id: I838be443a9521db23ca903ce3d5804cdf8bbf674
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138055
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/undobj.hxx b/sw/inc/undobj.hxx
index 2dd2d9b36610..51d406f84cb8 100644
--- a/sw/inc/undobj.hxx
+++ b/sw/inc/undobj.hxx
@@ -26,6 +26,7 @@
 #include "SwRewriter.hxx"
 #include "swundo.hxx"
 #include "nodeoffset.hxx"
+#include "ndindex.hxx"
 #include <o3tl/typed_flags_set.hxx>
 #include <optional>
 
@@ -37,7 +38,6 @@ class SwTextFormatColl;
 class SwFrameFormat;
 class SwFormatAnchor;
 class SwNode;
-class SwNodeIndex;
 class SwNodeRange;
 class SwRedlineData;
 class SwRedlineSaveDatas;
@@ -261,7 +261,7 @@ class SwUndoInserts : public SwUndo, public SwUndRng, 
private SwUndoSaveContent
 protected:
     SwNodeOffset m_nNodeDiff;
     /// start of Content in UndoNodes for Redo
-    std::unique_ptr<SwNodeIndex> m_pUndoNodeIndex;
+    std::optional<SwNodeIndex> m_oUndoNodeIndex;
     sal_uInt16 m_nSetPos;                 // Start in the history list.
 
     SwUndoInserts( SwUndoId nUndoId, const SwPaM& );
diff --git a/sw/source/core/undo/untblk.cxx b/sw/source/core/undo/untblk.cxx
index d03e1dca671c..a80c6502e38f 100644
--- a/sw/source/core/undo/untblk.cxx
+++ b/sw/source/core/undo/untblk.cxx
@@ -221,13 +221,13 @@ void SwUndoInserts::dumpAsXml(xmlTextWriterPtr pWriter) 
const
 
 SwUndoInserts::~SwUndoInserts()
 {
-    if (m_pUndoNodeIndex) // delete also the section from UndoNodes array
+    if (m_oUndoNodeIndex) // delete also the section from UndoNodes array
     {
         // Insert saves content in IconSection
-        SwNodes& rUNds = m_pUndoNodeIndex->GetNodes();
-        rUNds.Delete(*m_pUndoNodeIndex,
-            rUNds.GetEndOfExtras().GetIndex() - m_pUndoNodeIndex->GetIndex());
-        m_pUndoNodeIndex.reset();
+        SwNodes& rUNds = m_oUndoNodeIndex->GetNodes();
+        rUNds.Delete(*m_oUndoNodeIndex,
+            rUNds.GetEndOfExtras().GetIndex() - m_oUndoNodeIndex->GetIndex());
+        m_oUndoNodeIndex.reset();
     }
     m_pFrameFormats.reset();
     m_pRedlineData.reset();
@@ -311,9 +311,8 @@ void SwUndoInserts::UndoImpl(::sw::UndoRedoContext & 
rContext)
         m_nNodeDiff += nTmp - rPam.GetMark()->GetNodeIndex();
         if( *rPam.GetPoint() != *rPam.GetMark() )
         {
-            m_pUndoNodeIndex.reset(
-                    new SwNodeIndex(rDoc.GetNodes().GetEndOfContent()));
-            MoveToUndoNds(rPam, m_pUndoNodeIndex.get());
+            m_oUndoNodeIndex.emplace(rDoc.GetNodes().GetEndOfContent());
+            MoveToUndoNds(rPam, &*m_oUndoNodeIndex);
 
             if (m_nDeleteTextNodes == SwNodeOffset(0))
             {
@@ -387,16 +386,16 @@ void SwUndoInserts::RedoImpl(::sw::UndoRedoContext & 
rContext)
     m_pHistory->SetTmpEnd( m_nSetPos );
 
     // retrieve start position for rollback
-    if( ( m_nSttNode != m_nEndNode || m_nSttContent != m_nEndContent ) && 
m_pUndoNodeIndex)
+    if( ( m_nSttNode != m_nEndNode || m_nSttContent != m_nEndContent ) && 
m_oUndoNodeIndex)
     {
         auto const pFlysAtInsPos(sw::GetFlysAnchoredAt(rDoc,
             rPam.GetPoint()->GetNodeIndex()));
 
         const bool bMvBkwrd = MovePtBackward(rPam);
 
-        // re-insert content again (first detach m_pUndoNodeIndex!)
-        SwNodeOffset const nMvNd = m_pUndoNodeIndex->GetIndex();
-        m_pUndoNodeIndex.reset();
+        // re-insert content again (first detach m_oUndoNodeIndex!)
+        SwNodeOffset const nMvNd = m_oUndoNodeIndex->GetIndex();
+        m_oUndoNodeIndex.reset();
         MoveFromUndoNds(rDoc, nMvNd, *rPam.GetMark());
         if (m_nDeleteTextNodes != SwNodeOffset(0))
         {

Reply via email to