sw/inc/crsrsh.hxx | 3 ++- sw/inc/undobj.hxx | 6 +++--- sw/source/core/crsr/crsrsh.cxx | 10 ++++++---- sw/source/core/inc/UndoCore.hxx | 2 +- sw/source/core/undo/undobj.cxx | 20 ++++++++++---------- sw/source/core/undo/undobj1.cxx | 2 +- sw/source/uibase/docvw/edtwin.cxx | 4 ++-- sw/source/uibase/inc/wrtsh.hxx | 3 ++- sw/source/uibase/wrtsh/wrtsh1.cxx | 8 ++++---- 9 files changed, 31 insertions(+), 27 deletions(-)
New commits: commit a51509ee69b730e8987c149ac19e0bedccded127 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Mon Aug 8 14:31:31 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Aug 11 07:58:11 2022 +0200 unique_ptr->optional in SwUndoSaveSection Change-Id: I5fb07b35dbe3da55b6ca71537ac57dec9a5d0183 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138056 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 51d406f84cb8..7d1d38759529 100644 --- a/sw/inc/undobj.hxx +++ b/sw/inc/undobj.hxx @@ -200,13 +200,13 @@ public: // Save a complete section in nodes-array. class SwUndoSaveSection : private SwUndoSaveContent { - std::unique_ptr<SwNodeIndex> m_pMovedStart; + std::optional<SwNodeIndex> m_oMovedStart; std::unique_ptr<SwRedlineSaveDatas> m_pRedlineSaveData; SwNodeOffset m_nMoveLen; // Index into UndoNodes-Array. SwNodeOffset m_nStartPos; protected: - SwNodeIndex* GetMvSttIdx() const { return m_pMovedStart.get(); } + const SwNodeIndex* GetMvSttIdx() const { return m_oMovedStart ? &*m_oMovedStart : nullptr; } SwNodeOffset GetMvNodeCnt() const { return m_nMoveLen; } public: @@ -309,7 +309,7 @@ protected: SwUndoFlyBase( SwFrameFormat* pFormat, SwUndoId nUndoId ); - SwNodeIndex* GetMvSttIdx() const { return SwUndoSaveSection::GetMvSttIdx(); } + const SwNodeIndex* GetMvSttIdx() const { return SwUndoSaveSection::GetMvSttIdx(); } SwNodeOffset GetMvNodeCnt() const { return SwUndoSaveSection::GetMvNodeCnt(); } public: diff --git a/sw/source/core/inc/UndoCore.hxx b/sw/source/core/inc/UndoCore.hxx index c1c66b702a78..76d474adcc99 100644 --- a/sw/source/core/inc/UndoCore.hxx +++ b/sw/source/core/inc/UndoCore.hxx @@ -54,7 +54,7 @@ public: void RedlineToDoc( SwPaM const & rPam ); - SwNodeIndex* GetMvSttIdx() const + const SwNodeIndex* GetMvSttIdx() const { return SwUndoSaveSection::GetMvSttIdx(); } diff --git a/sw/source/core/undo/undobj.cxx b/sw/source/core/undo/undobj.cxx index b91eb0c6a0ac..3fc087bfc443 100644 --- a/sw/source/core/undo/undobj.cxx +++ b/sw/source/core/undo/undobj.cxx @@ -1212,14 +1212,14 @@ SwUndoSaveSection::SwUndoSaveSection() SwUndoSaveSection::~SwUndoSaveSection() { - if (m_pMovedStart) // delete also the section from UndoNodes array + if (m_oMovedStart) // delete also the section from UndoNodes array { // SaveSection saves the content in the PostIt section. - SwNodes& rUNds = m_pMovedStart->GetNode().GetNodes(); + SwNodes& rUNds = m_oMovedStart->GetNode().GetNodes(); // cid#1486004 Uncaught exception - suppress_fun_call_w_exception(rUNds.Delete(*m_pMovedStart, m_nMoveLen)); + suppress_fun_call_w_exception(rUNds.Delete(*m_oMovedStart, m_nMoveLen)); - m_pMovedStart.reset(); + m_oMovedStart.reset(); } m_pRedlineSaveData.reset(); } @@ -1272,9 +1272,9 @@ void SwUndoSaveSection::SaveSection( // Keep positions as SwContentIndex so that this section can be deleted in DTOR SwNodeOffset nEnd; - m_pMovedStart.reset(new SwNodeIndex(rRange.aStart)); - MoveToUndoNds(aPam, m_pMovedStart.get(), &nEnd); - m_nMoveLen = nEnd - m_pMovedStart->GetIndex() + 1; + m_oMovedStart = rRange.aStart; + MoveToUndoNds(aPam, &*m_oMovedStart, &nEnd); + m_nMoveLen = nEnd - m_oMovedStart->GetIndex() + 1; } void SwUndoSaveSection::RestoreSection( SwDoc* pDoc, SwNodeIndex* pIdx, @@ -1303,11 +1303,11 @@ void SwUndoSaveSection::RestoreSection( return; SwPosition aInsPos( rInsPos ); - SwNodeOffset nEnd = m_pMovedStart->GetIndex() + m_nMoveLen - 1; - MoveFromUndoNds(*pDoc, m_pMovedStart->GetIndex(), aInsPos, &nEnd, bForceCreateFrames); + SwNodeOffset nEnd = m_oMovedStart->GetIndex() + m_nMoveLen - 1; + MoveFromUndoNds(*pDoc, m_oMovedStart->GetIndex(), aInsPos, &nEnd, bForceCreateFrames); // destroy indices again, content was deleted from UndoNodes array - m_pMovedStart.reset(); + m_oMovedStart.reset(); m_nMoveLen = SwNodeOffset(0); if( m_pRedlineSaveData ) diff --git a/sw/source/core/undo/undobj1.cxx b/sw/source/core/undo/undobj1.cxx index 55b0f622d694..c8af10da32d6 100644 --- a/sw/source/core/undo/undobj1.cxx +++ b/sw/source/core/undo/undobj1.cxx @@ -444,7 +444,7 @@ SwRewriter SwUndoDelLayFormat::GetRewriter() const if (pDoc) { - SwNodeIndex* pIdx = GetMvSttIdx(); + const SwNodeIndex* pIdx = GetMvSttIdx(); if( SwNodeOffset(1) == GetMvNodeCnt() && pIdx) { SwNode *const pNd = & pIdx->GetNode(); commit 9685ae4470a4744f7cef525b8d67531e27235451 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Aug 10 14:37:24 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Aug 11 07:57:52 2022 +0200 no need to allocate SwCallLink on the heap Change-Id: Id1300d6eba82c7aaee41fc937e07a8f9a74bd076 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138088 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx index c2a5d75c454c..d0770ef65cbc 100644 --- a/sw/inc/crsrsh.hxx +++ b/sw/inc/crsrsh.hxx @@ -42,6 +42,7 @@ #include "node.hxx" #include "fldbas.hxx" #include "IDocumentMarkAccess.hxx" +#include <optional> class SfxItemSet; class SfxPoolItem; @@ -437,7 +438,7 @@ public: * stack * @return <true> if there was one on the stack, <false> otherwise */ - bool Pop(PopMode, ::std::unique_ptr<SwCallLink> pLink); + bool Pop(PopMode, ::std::optional<SwCallLink>& roLink); bool Pop(PopMode); /* * Combine 2 Cursors. diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx index 4b7fbcbd377d..f0cd5ac9a493 100644 --- a/sw/source/core/crsr/crsrsh.cxx +++ b/sw/source/core/crsr/crsrsh.cxx @@ -2268,14 +2268,16 @@ void SwCursorShell::Push() */ bool SwCursorShell::Pop(PopMode const eDelete) { - ::std::unique_ptr<SwCallLink> pLink(::std::make_unique<SwCallLink>(*this)); // watch Cursor-Moves; call Link if needed - return Pop(eDelete, ::std::move(pLink)); + std::optional<SwCallLink> aLink(std::in_place, *this); // watch Cursor-Moves; call Link if needed + return Pop(eDelete, aLink); } bool SwCursorShell::Pop(PopMode const eDelete, - [[maybe_unused]] ::std::unique_ptr<SwCallLink> const pLink) + [[maybe_unused]] std::optional<SwCallLink>& roLink) { - assert(pLink); // parameter exists only to be deleted before return + // parameter exists only to be deleted before return + assert(roLink); + comphelper::ScopeGuard aGuard( [&]() { roLink.reset(); } ); // are there any left? if (nullptr == m_pStackCursor) diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index b796270b9bdc..ea6752eb7ea1 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -6645,14 +6645,14 @@ Selection SwEditWin::GetSurroundingTextSelection() const TextFrameIndex const nPos(rSh.GetCursorPointAsViewIndex()); // store shell state *before* Push - ::std::unique_ptr<SwCallLink> pLink(::std::make_unique<SwCallLink>(rSh)); + ::std::optional<SwCallLink> aLink(std::in_place, rSh); rSh.Push(); rSh.HideCursor(); rSh.GoStartSentence(); TextFrameIndex const nStartPos(rSh.GetCursorPointAsViewIndex()); - rSh.Pop(SwCursorShell::PopMode::DeleteCurrent, ::std::move(pLink)); + rSh.Pop(SwCursorShell::PopMode::DeleteCurrent, aLink); rSh.ShowCursor(); if (bUnLockView) diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx index d8a0e2559624..fccf1ef81c4e 100644 --- a/sw/source/uibase/inc/wrtsh.hxx +++ b/sw/source/uibase/inc/wrtsh.hxx @@ -33,6 +33,7 @@ #include <doc.hxx> #include <docsh.hxx> #include <viewopt.hxx> +#include <optional> namespace vcl { class Window; } class SbxArray; @@ -146,7 +147,7 @@ public: // is there a text- or frameselection? bool HasSelection() const { return SwCursorShell::HasSelection() || IsMultiSelection() || IsSelFrameMode() || IsObjSelected(); } - bool Pop(SwCursorShell::PopMode, ::std::unique_ptr<SwCallLink> const pLink); + bool Pop(SwCursorShell::PopMode, ::std::optional<SwCallLink>& roLink); bool Pop(SwCursorShell::PopMode = SwCursorShell::PopMode::DeleteStack); void EnterStdMode(); diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index 805ec71f61d8..7ba0c8d49cd9 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -2014,13 +2014,13 @@ SwWrtShell::~SwWrtShell() bool SwWrtShell::Pop(SwCursorShell::PopMode const eDelete) { - ::std::unique_ptr<SwCallLink> pLink(::std::make_unique<SwCallLink>(*this)); - return Pop(eDelete, ::std::move(pLink)); + ::std::optional<SwCallLink> aLink(std::in_place, *this); + return Pop(eDelete, aLink); } -bool SwWrtShell::Pop(SwCursorShell::PopMode const eDelete, ::std::unique_ptr<SwCallLink> pLink) +bool SwWrtShell::Pop(SwCursorShell::PopMode const eDelete, ::std::optional<SwCallLink>& roLink) { - bool bRet = SwCursorShell::Pop(eDelete, ::std::move(pLink)); + bool bRet = SwCursorShell::Pop(eDelete, roLink); if( bRet && IsSelection() ) { if (!IsAddMode())