sw/source/core/crsr/bookmark.cxx | 16 ++++++++-------- sw/source/core/crsr/crossrefbookmark.cxx | 2 +- sw/source/core/doc/docfly.cxx | 10 +++++----- sw/source/core/frmedt/fecopy.cxx | 14 +++++++------- sw/source/core/inc/bookmark.hxx | 17 +++++++++-------- sw/source/core/inc/crossrefbookmark.hxx | 4 ++-- sw/source/core/text/redlnitr.cxx | 11 +++++------ sw/source/core/unocore/unoportenum.cxx | 8 ++++---- 8 files changed, 41 insertions(+), 41 deletions(-)
New commits: commit b1cefa026d52fad4557d10c721fe9d5e57200bd6 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Sun Aug 7 19:19:48 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sun Aug 7 20:36:00 2022 +0200 no need to allocate these SwPosition separately It is a small object, and in these places is already contained inside a heap object. Change-Id: I930d87827104e04fff2ad6b481ed94348a49701d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137930 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/core/crsr/bookmark.cxx b/sw/source/core/crsr/bookmark.cxx index 573b64602aab..a6c22c804e6b 100644 --- a/sw/source/core/crsr/bookmark.cxx +++ b/sw/source/core/crsr/bookmark.cxx @@ -268,15 +268,15 @@ namespace sw::mark { MarkBase::MarkBase(const SwPaM& aPaM, const OUString& rName) - : m_pPos1(new SwPosition(*(aPaM.GetPoint()))) + : m_oPos1(*aPaM.GetPoint()) , m_aName(rName) { - m_pPos1->SetMark(this); - lcl_FixPosition(*m_pPos1); + m_oPos1->SetMark(this); + lcl_FixPosition(*m_oPos1); if (aPaM.HasMark() && (*aPaM.GetMark() != *aPaM.GetPoint())) { MarkBase::SetOtherMarkPos(*(aPaM.GetMark())); - lcl_FixPosition(*m_pPos2); + lcl_FixPosition(*m_oPos2); } } @@ -293,14 +293,14 @@ namespace sw::mark void MarkBase::SetMarkPos(const SwPosition& rNewPos) { - std::make_unique<SwPosition>(rNewPos).swap(m_pPos1); - m_pPos1->SetMark(this); + m_oPos1.emplace(rNewPos); + m_oPos1->SetMark(this); } void MarkBase::SetOtherMarkPos(const SwPosition& rNewPos) { - std::make_unique<SwPosition>(rNewPos).swap(m_pPos2); - m_pPos2->SetMark(this); + m_oPos2.emplace(rNewPos); + m_oPos2->SetMark(this); } OUString MarkBase::ToString( ) const diff --git a/sw/source/core/crsr/crossrefbookmark.cxx b/sw/source/core/crsr/crossrefbookmark.cxx index 2976c2962a6d..61da186d39b9 100644 --- a/sw/source/core/crsr/crossrefbookmark.cxx +++ b/sw/source/core/crsr/crossrefbookmark.cxx @@ -46,7 +46,7 @@ namespace sw::mark "- creation of cross-reference bookmark with an illegal PaM that does not expand over exactly one whole paragraph."); if(rName.isEmpty()) m_aName = MarkBase::GenerateNewName(rPrefix); - assert(!m_pPos2); + assert(!m_oPos2); } void CrossRefBookmark::SetMarkPos(const SwPosition& rNewPos) diff --git a/sw/source/core/doc/docfly.cxx b/sw/source/core/doc/docfly.cxx index 9915e7de01b2..54d976f40677 100644 --- a/sw/source/core/doc/docfly.cxx +++ b/sw/source/core/doc/docfly.cxx @@ -767,11 +767,11 @@ bool SwDoc::ChgAnchor( const SdrMarkList& _rMrkList, // anchored object the complete <SwPosition> is kept, because the // anchor index position could be moved, if the object again is // anchored as character. - std::unique_ptr<const SwPosition> xOldAsCharAnchorPos; + std::optional<const SwPosition> oOldAsCharAnchorPos; const RndStdIds eOldAnchorType = pContact->GetAnchorId(); if ( !_bSameOnly && eOldAnchorType == RndStdIds::FLY_AS_CHAR ) { - xOldAsCharAnchorPos.reset(new SwPosition(pContact->GetContentAnchor())); + oOldAsCharAnchorPos.emplace(pContact->GetContentAnchor()); } if ( _bSameOnly ) @@ -973,7 +973,7 @@ bool SwDoc::ChgAnchor( const SdrMarkList& _rMrkList, pAnchoredObj->UpdateObjInSortedList(); // #i54336# - if (xOldAsCharAnchorPos) + if (oOldAsCharAnchorPos) { if ( pNewAnchorFrame) { @@ -981,8 +981,8 @@ bool SwDoc::ChgAnchor( const SdrMarkList& _rMrkList, // The TextAttribut needs to be destroyed which, unfortunately, also // destroys the format. To avoid that, we disconnect the format from // the attribute. - const sal_Int32 nIndx( xOldAsCharAnchorPos->GetContentIndex() ); - SwTextNode* pTextNode( xOldAsCharAnchorPos->GetNode().GetTextNode() ); + const sal_Int32 nIndx( oOldAsCharAnchorPos->GetContentIndex() ); + SwTextNode* pTextNode( oOldAsCharAnchorPos->GetNode().GetTextNode() ); assert(pTextNode && "<SwDoc::ChgAnchor(..)> - missing previous anchor text node for as-character anchored object"); SwTextAttr * const pHint = pTextNode->GetTextAttrForCharAt( nIndx, RES_TXTATR_FLYCNT ); diff --git a/sw/source/core/frmedt/fecopy.cxx b/sw/source/core/frmedt/fecopy.cxx index a6b95b39515b..68726cf5e196 100644 --- a/sw/source/core/frmedt/fecopy.cxx +++ b/sw/source/core/frmedt/fecopy.cxx @@ -577,20 +577,20 @@ bool SwFEShell::Copy( SwFEShell& rDestShell, const Point& rSttPt, aBoxes.empty() ? nullptr : aBoxes[0]->GetSttNd()->FindTableNode()); if (nullptr != pTableNd) { - std::unique_ptr<SwPosition> pDstPos; + std::optional<SwPosition> oDstPos; if( this == &rDestShell ) { // same shell? Then create new Cursor at the // DocumentPosition passed - pDstPos.reset(new SwPosition( *GetCursor()->GetPoint() )); + oDstPos.emplace( *GetCursor()->GetPoint() ); Point aPt( rInsPt ); - GetLayout()->GetModelPositionForViewPoint( pDstPos.get(), aPt ); - if( !pDstPos->GetNode().IsNoTextNode() ) + GetLayout()->GetModelPositionForViewPoint( &*oDstPos, aPt ); + if( !oDstPos->GetNode().IsNoTextNode() ) bRet = true; } else if( !rDestShell.GetCursor()->GetNode().IsNoTextNode() ) { - pDstPos.reset(new SwPosition( *rDestShell.GetCursor()->GetPoint() )); + oDstPos.emplace( *rDestShell.GetCursor()->GetPoint() ); bRet = true; } @@ -599,14 +599,14 @@ bool SwFEShell::Copy( SwFEShell& rDestShell, const Point& rSttPt, if( GetDoc() == rDestShell.GetDoc() ) ParkTableCursor(); - bRet = rDestShell.GetDoc()->InsCopyOfTable( *pDstPos, aBoxes,nullptr, + bRet = rDestShell.GetDoc()->InsCopyOfTable( *oDstPos, aBoxes,nullptr, bIsMove && this == &rDestShell && aBoxes.size() == pTableNd->GetTable(). GetTabSortBoxes().size(), this != &rDestShell ); if( this != &rDestShell ) - *rDestShell.GetCursor()->GetPoint() = *pDstPos; + *rDestShell.GetCursor()->GetPoint() = *oDstPos; // create all parked Cursor? if( GetDoc() == rDestShell.GetDoc() ) diff --git a/sw/source/core/inc/bookmark.hxx b/sw/source/core/inc/bookmark.hxx index 6e20feca5262..4413137bcb37 100644 --- a/sw/source/core/inc/bookmark.hxx +++ b/sw/source/core/inc/bookmark.hxx @@ -24,6 +24,7 @@ #include <vcl/keycod.hxx> #include <unotools/weakref.hxx> #include <memory> +#include <optional> #include <string_view> #include <com/sun/star/text/XTextContent.hpp> @@ -48,13 +49,13 @@ namespace sw::mark { public: //getters virtual SwPosition& GetMarkPos() const override - { return *m_pPos1; } + { return const_cast<SwPosition&>(*m_oPos1); } virtual const OUString& GetName() const override { return m_aName; } virtual SwPosition& GetOtherMarkPos() const override { OSL_PRECOND(IsExpanded(), "<SwPosition::GetOtherMarkPos(..)> - I have no other Pos set." ); - return *m_pPos2; + return const_cast<SwPosition&>(*m_oPos2); } virtual SwPosition& GetMarkStart() const override { @@ -75,14 +76,14 @@ namespace sw::mark { virtual bool IsCoveringPosition(const SwPosition& rPos) const override; virtual bool IsExpanded() const override - { return static_cast< bool >(m_pPos2); } + { return m_oPos2.has_value(); } void SetName(const OUString& rName) { m_aName = rName; } virtual void SetMarkPos(const SwPosition& rNewPos); virtual void SetOtherMarkPos(const SwPosition& rNewPos); virtual void ClearOtherMarkPos() - { m_pPos2.reset(); } + { m_oPos2.reset(); } virtual auto InvalidateFrames() -> void; @@ -91,8 +92,8 @@ namespace sw::mark { void Swap() { - if(m_pPos2) - m_pPos1.swap(m_pPos2); + if(m_oPos2) + m_oPos1.swap(m_oPos2); } virtual void InitDoc(SwDoc&, sw::mark::InsertMode, SwPosition const*) @@ -110,8 +111,8 @@ namespace sw::mark { virtual void SwClientNotify(const SwModify&, const SfxHint&) override; MarkBase(const SwPaM& rPaM, const OUString& rName); - std::unique_ptr<SwPosition> m_pPos1; - std::unique_ptr<SwPosition> m_pPos2; + std::optional<SwPosition> m_oPos1; + std::optional<SwPosition> m_oPos2; OUString m_aName; static OUString GenerateNewName(std::u16string_view rPrefix); diff --git a/sw/source/core/inc/crossrefbookmark.hxx b/sw/source/core/inc/crossrefbookmark.hxx index 2540170c9407..3ee770e8d6e0 100644 --- a/sw/source/core/inc/crossrefbookmark.hxx +++ b/sw/source/core/inc/crossrefbookmark.hxx @@ -41,9 +41,9 @@ namespace sw::mark { // getters virtual SwPosition& GetOtherMarkPos() const override; virtual SwPosition& GetMarkStart() const override - { return *m_pPos1; } + { return const_cast<SwPosition&>(*m_oPos1); } virtual SwPosition& GetMarkEnd() const override - { return *m_pPos1; } + { return const_cast<SwPosition&>(*m_oPos1); } virtual bool IsExpanded() const override { return false; } diff --git a/sw/source/core/text/redlnitr.cxx b/sw/source/core/text/redlnitr.cxx index b26cf5f4bdcc..e826141a9afa 100644 --- a/sw/source/core/text/redlnitr.cxx +++ b/sw/source/core/text/redlnitr.cxx @@ -66,7 +66,7 @@ private: /// next redline SwRedlineTable::size_type m_RedlineIndex; /// next fieldmark - std::pair<sw::mark::IFieldmark const*, std::unique_ptr<SwPosition>> m_Fieldmark; + std::pair<sw::mark::IFieldmark const*, std::optional<SwPosition>> m_Fieldmark; std::optional<SwPosition> m_oNextFieldmarkHide; /// current start/end pair SwPosition const* m_pStartPos; @@ -154,15 +154,14 @@ public: // always hide the CH_TXT_ATR_FIELDSEP for now if (m_eFieldmarkMode == sw::FieldmarkMode::ShowResult) { - m_Fieldmark.second.reset( - new SwPosition(sw::mark::FindFieldSep(*m_Fieldmark.first))); + m_Fieldmark.second.emplace( + sw::mark::FindFieldSep(*m_Fieldmark.first)); ++m_Fieldmark.second->nContent; ++m_oNextFieldmarkHide->nContent; // skip start } else { - m_Fieldmark.second.reset( - new SwPosition(pFieldmark->GetMarkEnd())); + m_Fieldmark.second.emplace(pFieldmark->GetMarkEnd()); --m_Fieldmark.second->nContent; } } @@ -186,7 +185,7 @@ public: { assert(!pNextRedlineHide || *m_oNextFieldmarkHide <= *pNextRedlineHide); m_pStartPos = &*m_oNextFieldmarkHide; - m_pEndPos = m_Fieldmark.second.get(); + m_pEndPos = &*m_Fieldmark.second; return true; } else // nothing diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx index 7d37e1e87900..f8e2df566283 100644 --- a/sw/source/core/unocore/unoportenum.cxx +++ b/sw/source/core/unocore/unoportenum.cxx @@ -149,7 +149,7 @@ namespace if(rEndPos.nNode != nOwnNode) return; - unique_ptr<SwPosition> pCrossRefEndPos; + std::optional<SwPosition> oCrossRefEndPos; const SwPosition* pEndPos = nullptr; ::sw::mark::CrossRefBookmark *const pCrossRefMark(dynamic_cast< ::sw::mark::CrossRefBookmark*>(pBkmk)); if(hasOther) @@ -159,9 +159,9 @@ namespace else if (pCrossRefMark) { // Crossrefbookmarks only remember the start position but have to span the whole paragraph - pCrossRefEndPos = std::make_unique<SwPosition>(rEndPos); - pCrossRefEndPos->nContent = pCrossRefEndPos->GetNode().GetTextNode()->Len(); - pEndPos = pCrossRefEndPos.get(); + oCrossRefEndPos.emplace(rEndPos); + oCrossRefEndPos->nContent = oCrossRefEndPos->GetNode().GetTextNode()->Len(); + pEndPos = &*oCrossRefEndPos; } if(pEndPos) {