sw/source/core/inc/frame.hxx | 8 +++-- sw/source/core/inc/pagefrm.hxx | 6 ++-- sw/source/core/layout/calcmove.cxx | 8 ++--- sw/source/core/layout/fly.cxx | 45 +++++++++++++++++++-------------- sw/source/core/layout/flylay.cxx | 15 +++++------ sw/source/core/layout/pagechg.cxx | 6 +--- sw/source/core/layout/ssfrm.cxx | 11 +++----- sw/source/core/layout/wsfrm.cxx | 1 sw/source/core/swg/SwXMLTextBlocks.cxx | 7 +---- 9 files changed, 55 insertions(+), 52 deletions(-)
New commits: commit 16e75d4b5df6d516873c2dcb39442d4bbda1efed Author: Michael Stahl <mst...@redhat.com> Date: Thu Jan 4 15:54:31 2018 +0100 sw: replace local DELETEZ with unique_ptr Change-Id: I8c650a1dce327c5f4651e166ea998db0fd2292cd diff --git a/sw/source/core/swg/SwXMLTextBlocks.cxx b/sw/source/core/swg/SwXMLTextBlocks.cxx index 87fdb2b3c40a..c6d219d6fc95 100644 --- a/sw/source/core/swg/SwXMLTextBlocks.cxx +++ b/sw/source/core/swg/SwXMLTextBlocks.cxx @@ -336,7 +336,7 @@ ErrCode SwXMLTextBlocks::PutBlock() if ( xRoot.is() ) { - SfxMedium* pTmpMedium = nullptr; + std::unique_ptr<SfxMedium> pTmpMedium; try { uno::Reference< embed::XStorage > xTempStorage = @@ -346,7 +346,7 @@ ErrCode SwXMLTextBlocks::PutBlock() // TODO/LATER: no progress bar?! // TODO/MBA: strange construct - pTmpMedium = new SfxMedium( xTempStorage, GetBaseURL() ); + pTmpMedium.reset(new SfxMedium(xTempStorage, GetBaseURL())); bool bTmpOK = pDocSh->SaveAsChildren( *pTmpMedium ); if( bTmpOK ) bTmpOK = pDocSh->SaveCompletedChildren(); @@ -357,9 +357,6 @@ ErrCode SwXMLTextBlocks::PutBlock() catch(const uno::Exception&) { } - - if ( pTmpMedium ) - DELETEZ( pTmpMedium ); } if( !bOK ) commit 0af086beaaad8ded4f551ece0086ce990952ee16 Author: Michael Stahl <mst...@redhat.com> Date: Thu Jan 4 15:52:06 2018 +0100 sw: convert SwPageFrame::m_pSortedObjs to unique_ptr Change-Id: Id0cac6143c4c9278fc450048cc0b276d72d0c1a1 diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx index d49b5275893d..8c7ab3a92fdb 100644 --- a/sw/source/core/inc/pagefrm.hxx +++ b/sw/source/core/inc/pagefrm.hxx @@ -42,7 +42,7 @@ class SwPageFrame: public SwFootnoteBossFrame { friend class SwFrame; - SwSortedObjs *m_pSortedObjs; + std::unique_ptr<SwSortedObjs> m_pSortedObjs; SwPageDesc *m_pDesc; //PageDesc that describes the Page @@ -117,8 +117,8 @@ public: void PrepareHeader(); void PrepareFooter(); - const SwSortedObjs *GetSortedObjs() const { return m_pSortedObjs; } - SwSortedObjs *GetSortedObjs() { return m_pSortedObjs; } + const SwSortedObjs *GetSortedObjs() const { return m_pSortedObjs.get(); } + SwSortedObjs *GetSortedObjs() { return m_pSortedObjs.get(); } void AppendDrawObjToPage( SwAnchoredObject& _rNewObj ); void RemoveDrawObjFromPage( SwAnchoredObject& _rToRemoveObj ); diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx index 6057b2115b28..16f30d320444 100644 --- a/sw/source/core/layout/calcmove.cxx +++ b/sw/source/core/layout/calcmove.cxx @@ -644,11 +644,11 @@ void SwFrame::MakePos() } // #i28701# - new type <SwSortedObjs> -static void lcl_CheckObjects( SwSortedObjs* pSortedObjs, const SwFrame* pFrame, long& rBot ) +static void lcl_CheckObjects(SwSortedObjs& rSortedObjs, const SwFrame* pFrame, long& rBot) { // And then there can be paragraph anchored frames that sit below their paragraph. long nMax = 0; - for (SwAnchoredObject* pObj : *pSortedObjs) + for (SwAnchoredObject* pObj : rSortedObjs) { // #i28701# - consider changed type of <SwSortedObjs> // entries. @@ -729,13 +729,13 @@ size_t SwPageFrame::GetContentHeight(const long nTop, const long nBottom) const // protrude outside the Body/FootnoteCont. if (m_pSortedObjs && !pFrame->IsHeaderFrame() && !pFrame->IsFooterFrame()) - lcl_CheckObjects(m_pSortedObjs, pFrame, nBot); + lcl_CheckObjects(*m_pSortedObjs, pFrame, nBot); pFrame = pFrame->GetNext(); } nBot += nBottom; // And the page anchored ones if (m_pSortedObjs) - lcl_CheckObjects(m_pSortedObjs, this, nBot); + lcl_CheckObjects(*m_pSortedObjs, this, nBot); nBot -= getFrameArea().Top(); return nBot; diff --git a/sw/source/core/layout/flylay.cxx b/sw/source/core/layout/flylay.cxx index ae487ebee352..b57b763d8e79 100644 --- a/sw/source/core/layout/flylay.cxx +++ b/sw/source/core/layout/flylay.cxx @@ -826,7 +826,9 @@ void SwPageFrame::AppendFlyToPage( SwFlyFrame *pNew ) InvalidateFlyContent(); if ( !m_pSortedObjs ) - m_pSortedObjs = new SwSortedObjs(); + { + m_pSortedObjs.reset(new SwSortedObjs()); + } const bool bSuccessInserted = m_pSortedObjs->Insert( *pNew ); OSL_ENSURE( bSuccessInserted, "Fly not inserted in Sorted." ); @@ -910,8 +912,7 @@ void SwPageFrame::RemoveFlyFromPage( SwFlyFrame *pToRemove ) m_pSortedObjs->Remove(*pToRemove); if (!m_pSortedObjs->size()) { - delete m_pSortedObjs; - m_pSortedObjs = nullptr; + m_pSortedObjs.reset(); } } @@ -968,13 +969,13 @@ void SwPageFrame::MoveFly( SwFlyFrame *pToMove, SwPageFrame *pDest ) m_pSortedObjs->Remove( *pToMove ); if ( !m_pSortedObjs->size() ) { - DELETEZ( m_pSortedObjs ); + m_pSortedObjs.reset(); } } // Register if ( !pDest->GetSortedObjs() ) - pDest->m_pSortedObjs = new SwSortedObjs(); + pDest->m_pSortedObjs.reset(new SwSortedObjs()); const bool bSuccessInserted = pDest->GetSortedObjs()->Insert( *pToMove ); OSL_ENSURE( bSuccessInserted, "Fly not inserted in Sorted." ); @@ -1059,7 +1060,7 @@ void SwPageFrame::AppendDrawObjToPage( SwAnchoredObject& _rNewObj ) if ( !m_pSortedObjs ) { - m_pSortedObjs = new SwSortedObjs(); + m_pSortedObjs.reset(new SwSortedObjs()); } if ( !m_pSortedObjs->Insert( _rNewObj ) ) { @@ -1088,7 +1089,7 @@ void SwPageFrame::RemoveDrawObjFromPage( SwAnchoredObject& _rToRemoveObj ) m_pSortedObjs->Remove( _rToRemoveObj ); if ( !m_pSortedObjs->size() ) { - DELETEZ( m_pSortedObjs ); + m_pSortedObjs.reset(); } if ( GetUpper() ) { diff --git a/sw/source/core/layout/pagechg.cxx b/sw/source/core/layout/pagechg.cxx index 79abcfdf6f56..58ffeed1a424 100644 --- a/sw/source/core/layout/pagechg.cxx +++ b/sw/source/core/layout/pagechg.cxx @@ -169,7 +169,6 @@ void SwBodyFrame::Format( vcl::RenderContext* /*pRenderContext*/, const SwBorder SwPageFrame::SwPageFrame( SwFrameFormat *pFormat, SwFrame* pSib, SwPageDesc *pPgDsc ) : SwFootnoteBossFrame( pFormat, pSib ), - m_pSortedObjs( nullptr ), m_pDesc( pPgDsc ), m_nPhyPageNum( 0 ) { @@ -261,7 +260,7 @@ void SwPageFrame::DestroyImpl() } // empty FlyContainer, deletion of the Flys is done by the anchor (in base class SwFrame) - if ( m_pSortedObjs ) + if (m_pSortedObjs) { // Objects can be anchored at pages that are before their anchors (why ever...). // In such cases, we would access already freed memory. @@ -269,8 +268,7 @@ void SwPageFrame::DestroyImpl() { pAnchoredObj->SetPageFrame( nullptr ); } - delete m_pSortedObjs; - m_pSortedObjs = nullptr; // reset to zero to prevent problems when detaching the Flys + m_pSortedObjs.reset(); // reset to zero to prevent problems when detaching the Flys } if ( !IsEmptyPage() ) //#59184# unnecessary for empty pages commit 794e54cd34239006270a00a6e5017acc463063f9 Author: Michael Stahl <mst...@redhat.com> Date: Thu Jan 4 15:35:21 2018 +0100 sw: convert SwFrame::mpDrawObjs to unique_ptr Change-Id: I0713e6fb2b3f2cfc3115daafe37ae5380f3e7938 diff --git a/sw/source/core/inc/frame.hxx b/sw/source/core/inc/frame.hxx index 9d3ca61708de..7ecbefc600a9 100644 --- a/sw/source/core/inc/frame.hxx +++ b/sw/source/core/inc/frame.hxx @@ -32,6 +32,8 @@ #include <com/sun/star/style/TabStop.hpp> #include <basegfx/matrix/b2dhommatrix.hxx> +#include <memory> + class SwLayoutFrame; class SwRootFrame; class SwPageFrame; @@ -378,7 +380,7 @@ class SW_DLLPUBLIC SwFrame : public SwFrameAreaDefinition, public SwClient, publ SwPageFrame* ImplFindPageFrame(); protected: - SwSortedObjs* mpDrawObjs; // draw objects, can be 0 + std::unique_ptr<SwSortedObjs> m_pDrawObjs; // draw objects, can be null SwFrameType mnFrameType; //Who am I? bool mbInDtor : 1; @@ -524,8 +526,8 @@ public: // work with chain of FlyFrames void AppendFly( SwFlyFrame *pNew ); void RemoveFly( SwFlyFrame *pToRemove ); - const SwSortedObjs *GetDrawObjs() const { return mpDrawObjs; } - SwSortedObjs *GetDrawObjs() { return mpDrawObjs; } + const SwSortedObjs *GetDrawObjs() const { return m_pDrawObjs.get(); } + SwSortedObjs *GetDrawObjs() { return m_pDrawObjs.get(); } // #i28701# - change purpose of method and adjust its name void InvalidateObjs( const bool _bNoInvaOfAsCharAnchoredObjs = true ); diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx index b4d05f138fbf..0daef994f355 100644 --- a/sw/source/core/layout/fly.cxx +++ b/sw/source/core/layout/fly.cxx @@ -2007,9 +2007,11 @@ void SwFlyFrame::Cut() void SwFrame::AppendFly( SwFlyFrame *pNew ) { - if ( !mpDrawObjs ) - mpDrawObjs = new SwSortedObjs(); - mpDrawObjs->Insert( *pNew ); + if (!m_pDrawObjs) + { + m_pDrawObjs.reset(new SwSortedObjs()); + } + m_pDrawObjs->Insert( *pNew ); pNew->ChgAnchorFrame( this ); // Register at the page @@ -2049,9 +2051,11 @@ void SwFrame::RemoveFly( SwFlyFrame *pToRemove ) } } - mpDrawObjs->Remove( *pToRemove ); - if ( !mpDrawObjs->size() ) - DELETEZ( mpDrawObjs ); + m_pDrawObjs->Remove(*pToRemove); + if (!m_pDrawObjs->size()) + { + m_pDrawObjs.reset(); + } pToRemove->ChgAnchorFrame( nullptr ); @@ -2061,7 +2065,7 @@ void SwFrame::RemoveFly( SwFlyFrame *pToRemove ) void SwFrame::AppendDrawObj( SwAnchoredObject& _rNewObj ) { - assert(!mpDrawObjs || mpDrawObjs->is_sorted()); + assert(!m_pDrawObjs || m_pDrawObjs->is_sorted()); if ( dynamic_cast<const SwAnchoredDrawObject*>( &_rNewObj) == nullptr ) { @@ -2072,19 +2076,21 @@ void SwFrame::AppendDrawObj( SwAnchoredObject& _rNewObj ) if ( dynamic_cast<const SwDrawVirtObj*>(_rNewObj.GetDrawObj()) == nullptr && _rNewObj.GetAnchorFrame() && _rNewObj.GetAnchorFrame() != this ) { - assert(!mpDrawObjs || mpDrawObjs->is_sorted()); + assert(!m_pDrawObjs || m_pDrawObjs->is_sorted()); // perform disconnect from layout, if 'master' drawing object is appended // to a new frame. static_cast<SwDrawContact*>(::GetUserCall( _rNewObj.GetDrawObj() ))-> DisconnectFromLayout( false ); - assert(!mpDrawObjs || mpDrawObjs->is_sorted()); + assert(!m_pDrawObjs || m_pDrawObjs->is_sorted()); } if ( _rNewObj.GetAnchorFrame() != this ) { - if ( !mpDrawObjs ) - mpDrawObjs = new SwSortedObjs(); - mpDrawObjs->Insert( _rNewObj ); + if (!m_pDrawObjs) + { + m_pDrawObjs.reset(new SwSortedObjs()); + } + m_pDrawObjs->Insert(_rNewObj); _rNewObj.ChgAnchorFrame( this ); } @@ -2110,7 +2116,7 @@ void SwFrame::AppendDrawObj( SwAnchoredObject& _rNewObj ) } //The layer is part of the key used to sort the obj, so update //its position if the layer changed. - mpDrawObjs->Update(_rNewObj); + m_pDrawObjs->Update(_rNewObj); } } @@ -2135,7 +2141,7 @@ void SwFrame::AppendDrawObj( SwAnchoredObject& _rNewObj ) } } - assert(!mpDrawObjs || mpDrawObjs->is_sorted()); + assert(!m_pDrawObjs || m_pDrawObjs->is_sorted()); } void SwFrame::RemoveDrawObj( SwAnchoredObject& _rToRemoveObj ) @@ -2154,13 +2160,14 @@ void SwFrame::RemoveDrawObj( SwAnchoredObject& _rToRemoveObj ) if ( pPage && pPage->GetSortedObjs() ) pPage->RemoveDrawObjFromPage( _rToRemoveObj ); - mpDrawObjs->Remove( _rToRemoveObj ); - if ( !mpDrawObjs->size() ) - DELETEZ( mpDrawObjs ); - + m_pDrawObjs->Remove(_rToRemoveObj); + if (!m_pDrawObjs->size()) + { + m_pDrawObjs.reset(); + } _rToRemoveObj.ChgAnchorFrame( nullptr ); - assert(!mpDrawObjs || mpDrawObjs->is_sorted()); + assert(!m_pDrawObjs || m_pDrawObjs->is_sorted()); } void SwFrame::InvalidateObjs( const bool _bNoInvaOfAsCharAnchoredObjs ) diff --git a/sw/source/core/layout/ssfrm.cxx b/sw/source/core/layout/ssfrm.cxx index 9934d1c4b4dd..180ceba1ff9c 100644 --- a/sw/source/core/layout/ssfrm.cxx +++ b/sw/source/core/layout/ssfrm.cxx @@ -338,11 +338,11 @@ void SwFrame::DestroyImpl() } } - if( mpDrawObjs ) + if (m_pDrawObjs) { - for ( size_t i = mpDrawObjs->size(); i; ) + for (size_t i = m_pDrawObjs->size(); i; ) { - SwAnchoredObject* pAnchoredObj = (*mpDrawObjs)[--i]; + SwAnchoredObject* pAnchoredObj = (*m_pDrawObjs)[--i]; if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) != nullptr ) { SwFrame::DestroyFrame(static_cast<SwFlyFrame*>(pAnchoredObj)); @@ -360,8 +360,7 @@ void SwFrame::DestroyImpl() } } } - delete mpDrawObjs; - mpDrawObjs = nullptr; + m_pDrawObjs.reset(); } } @@ -371,7 +370,7 @@ SwFrame::~SwFrame() assert(!IsDeleteForbidden()); // check that it's not deleted while deletes are forbidden #if OSL_DEBUG_LEVEL > 0 // JP 15.10.2001: for detection of access to deleted frames - mpDrawObjs = reinterpret_cast<SwSortedObjs*>(0x33333333); + mpRoot = reinterpret_cast<SwRootFrame*>(0x33333333); #endif } diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx index be7264c424e0..5b85b69a4b27 100644 --- a/sw/source/core/layout/wsfrm.cxx +++ b/sw/source/core/layout/wsfrm.cxx @@ -297,7 +297,6 @@ SwFrame::SwFrame( SwModify *pMod, SwFrame* pSib ) mpUpper(nullptr), mpNext(nullptr), mpPrev(nullptr), - mpDrawObjs(nullptr), mnFrameType(SwFrameType::None), mbInDtor(false), mbInvalidR2L(true), _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits