diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-08-20 09:53:33 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-08-21 08:35:33 +0200 |
commit | 06765e45cbf83a865cabb3ce6c418f497e87e099 (patch) | |
tree | 6c0fbb83f473e2c4765c78005107a98b3fbbf4c3 /sfx2 | |
parent | 1188bebbc53d0519733cfe98cfab4d83474e8ddf (diff) |
loplugin:useuniqueptr in DeleteItemOnIdle
Change-Id: I6a72417bcab1ac48b5d8a73005104c8627dde32b
Reviewed-on: https://gerrit.libreoffice.org/59349
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/control/bindings.cxx | 17 | ||||
-rw-r--r-- | sfx2/source/control/itemdel.cxx | 10 | ||||
-rw-r--r-- | sfx2/source/control/request.cxx | 15 | ||||
-rw-r--r-- | sfx2/source/control/shell.cxx | 11 | ||||
-rw-r--r-- | sfx2/source/inc/itemdel.hxx | 4 |
5 files changed, 27 insertions, 30 deletions
diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx index f6454d2a31f3..b65ccbf08892 100644 --- a/sfx2/source/control/bindings.cxx +++ b/sfx2/source/control/bindings.cxx @@ -925,14 +925,15 @@ const SfxPoolItem* SfxBindings::Execute_Impl( sal_uInt16 nId, const SfxPoolItem* // cache binds to an external dispatch provider sal_Int16 eRet = pCache->Dispatch( aReq.GetArgs(), nCallMode == SfxCallMode::SYNCHRON ); - SfxPoolItem *pPool; + std::unique_ptr<SfxPoolItem> pPool; if ( eRet == css::frame::DispatchResultState::DONTKNOW ) - pPool = new SfxVoidItem( nId ); + pPool.reset( new SfxVoidItem( nId ) ); else - pPool = new SfxBoolItem( nId, eRet == css::frame::DispatchResultState::SUCCESS); + pPool.reset( new SfxBoolItem( nId, eRet == css::frame::DispatchResultState::SUCCESS) ); - DeleteItemOnIdle( pPool ); - return pPool; + auto pTemp = pPool.get(); + DeleteItemOnIdle( std::move(pPool) ); + return pTemp; } // slot is handled internally by SfxDispatcher @@ -976,9 +977,9 @@ const SfxPoolItem* SfxBindings::Execute_Impl( sal_uInt16 nId, const SfxPoolItem* const SfxPoolItem* pRet = aReq.GetReturnValue(); if ( !pRet ) { - SfxPoolItem *pVoid = new SfxVoidItem( nId ); - DeleteItemOnIdle( pVoid ); - pRet = pVoid; + std::unique_ptr<SfxPoolItem> pVoid(new SfxVoidItem( nId )); + pRet = pVoid.get(); + DeleteItemOnIdle( std::move(pVoid) ); } return pRet; diff --git a/sfx2/source/control/itemdel.cxx b/sfx2/source/control/itemdel.cxx index d0555950dd39..4dbd6bb22171 100644 --- a/sfx2/source/control/itemdel.cxx +++ b/sfx2/source/control/itemdel.cxx @@ -33,15 +33,15 @@ private: DECL_LINK( Delete, Timer*, void ); public: - explicit SfxItemDisruptor_Impl(SfxPoolItem *pItemToDesrupt); + explicit SfxItemDisruptor_Impl(std::unique_ptr<SfxPoolItem> pItemToDesrupt); void LaunchDeleteOnIdle(); ~SfxItemDisruptor_Impl(); SfxItemDisruptor_Impl(const SfxItemDisruptor_Impl&) = delete; SfxItemDisruptor_Impl& operator=(const SfxItemDisruptor_Impl&) = delete; }; -SfxItemDisruptor_Impl::SfxItemDisruptor_Impl(SfxPoolItem *const pItemToDisrupt) - : pItem(pItemToDisrupt) +SfxItemDisruptor_Impl::SfxItemDisruptor_Impl(std::unique_ptr<SfxPoolItem> pItemToDisrupt) + : pItem(std::move(pItemToDisrupt)) , m_Idle("sfx SfxItemDisruptor_Impl::Delete") { m_Idle.SetInvokeHandler(LINK(this, SfxItemDisruptor_Impl, Delete)); @@ -72,10 +72,10 @@ IMPL_LINK_NOARG(SfxItemDisruptor_Impl, Delete, Timer*, void) delete this; } -void DeleteItemOnIdle(SfxPoolItem* pItem) +void DeleteItemOnIdle(std::unique_ptr<SfxPoolItem> pItem) { DBG_ASSERT( 0 == pItem->GetRefCount(), "deleting item in use" ); - SfxItemDisruptor_Impl *pDesruptor = new SfxItemDisruptor_Impl(pItem); + SfxItemDisruptor_Impl *pDesruptor = new SfxItemDisruptor_Impl(std::move(pItem)); pDesruptor->LaunchDeleteOnIdle(); // coverity[leaked_storage] - pDesruptor takes care of its own destruction at idle time } diff --git a/sfx2/source/control/request.cxx b/sfx2/source/control/request.cxx index ece383994c26..7c73d3664c8e 100644 --- a/sfx2/source/control/request.cxx +++ b/sfx2/source/control/request.cxx @@ -57,7 +57,7 @@ struct SfxRequest_Impl: public SfxListener SfxRequest* pAnti; // Owner because of dying pool OUString aTarget; // if possible from target object set by App SfxItemPool* pPool; // ItemSet build with this pool - SfxPoolItem* pRetVal; // Return value belongs to itself + std::unique_ptr<SfxPoolItem> pRetVal; // Return value belongs to itself SfxShell* pShell; // run from this shell const SfxSlot* pSlot; // executed Slot sal_uInt16 nModifier; // which Modifier was pressed? @@ -76,7 +76,6 @@ struct SfxRequest_Impl: public SfxListener explicit SfxRequest_Impl( SfxRequest *pOwner ) : pAnti( pOwner) , pPool(nullptr) - , pRetVal(nullptr) , pShell(nullptr) , pSlot(nullptr) , nModifier(0) @@ -125,7 +124,7 @@ SfxRequest::~SfxRequest() // Clear object pArgs.reset(); if ( pImpl->pRetVal ) - DeleteItemOnIdle(pImpl->pRetVal); + DeleteItemOnIdle(std::move(pImpl->pRetVal)); } @@ -141,7 +140,6 @@ SfxRequest::SfxRequest pImpl->bAllowRecording = rOrig.pImpl->bAllowRecording; pImpl->bDone = false; pImpl->bIgnored = false; - pImpl->pRetVal = nullptr; pImpl->pShell = nullptr; pImpl->pSlot = nullptr; pImpl->nCallMode = rOrig.pImpl->nCallMode; @@ -198,7 +196,6 @@ SfxRequest::SfxRequest pImpl->bDone = false; pImpl->bIgnored = false; pImpl->SetPool( &pViewFrame->GetPool() ); - pImpl->pRetVal = nullptr; pImpl->pShell = nullptr; pImpl->pSlot = nullptr; pImpl->nCallMode = SfxCallMode::SYNCHRON; @@ -232,7 +229,6 @@ SfxRequest::SfxRequest pImpl->bDone = false; pImpl->bIgnored = false; pImpl->SetPool( &rPool ); - pImpl->pRetVal = nullptr; pImpl->pShell = nullptr; pImpl->pSlot = nullptr; pImpl->nCallMode = nMode; @@ -252,7 +248,6 @@ SfxRequest::SfxRequest pImpl->bDone = false; pImpl->bIgnored = false; pImpl->SetPool( &rPool ); - pImpl->pRetVal = nullptr; pImpl->pShell = nullptr; pImpl->pSlot = nullptr; pImpl->nCallMode = nMode; @@ -276,7 +271,6 @@ SfxRequest::SfxRequest pImpl->bDone = false; pImpl->bIgnored = false; pImpl->SetPool( rSfxArgs.GetPool() ); - pImpl->pRetVal = nullptr; pImpl->pShell = nullptr; pImpl->pSlot = nullptr; pImpl->nCallMode = nMode; @@ -432,14 +426,13 @@ void SfxRequest::RemoveItem( sal_uInt16 nID ) void SfxRequest::SetReturnValue(const SfxPoolItem &rItem) { DBG_ASSERT(!pImpl->pRetVal, "Set Return value multiple times?"); - delete pImpl->pRetVal; - pImpl->pRetVal = rItem.Clone(); + pImpl->pRetVal.reset(rItem.Clone()); } const SfxPoolItem* SfxRequest::GetReturnValue() const { - return pImpl->pRetVal; + return pImpl->pRetVal.get(); } diff --git a/sfx2/source/control/shell.cxx b/sfx2/source/control/shell.cxx index 42ff95827f77..6d5e1fd137c7 100644 --- a/sfx2/source/control/shell.cxx +++ b/sfx2/source/control/shell.cxx @@ -491,7 +491,7 @@ const SfxPoolItem* SfxShell::GetSlotState eState = SfxItemState::UNKNOWN; // Evaluate Item and item status and possibly maintain them in pStateSet - SfxPoolItem *pRetItem = nullptr; + std::unique_ptr<SfxPoolItem> pRetItem; if ( eState <= SfxItemState::DISABLED ) { if ( pStateSet ) @@ -502,17 +502,18 @@ const SfxPoolItem* SfxShell::GetSlotState { if ( pStateSet ) pStateSet->ClearItem(nSlotId); - pRetItem = new SfxVoidItem(0); + pRetItem.reset( new SfxVoidItem(0) ); } else { if ( pStateSet && pStateSet->Put( *pItem ) ) return &pStateSet->Get( pItem->Which() ); - pRetItem = pItem->Clone(); + pRetItem.reset(pItem->Clone()); } - DeleteItemOnIdle(pRetItem); + auto pTemp = pRetItem.get(); + DeleteItemOnIdle(std::move(pRetItem)); - return pRetItem; + return pTemp; } SFX_EXEC_STUB(SfxShell, VerbExec) diff --git a/sfx2/source/inc/itemdel.hxx b/sfx2/source/inc/itemdel.hxx index cd5d14de170e..1884c83c38cc 100644 --- a/sfx2/source/inc/itemdel.hxx +++ b/sfx2/source/inc/itemdel.hxx @@ -19,9 +19,11 @@ #ifndef INCLUDED_SFX2_ITEMDEL_HXX #define INCLUDED_SFX2_ITEMDEL_HXX +#include <memory> + class SfxPoolItem; -void DeleteItemOnIdle( SfxPoolItem* pItem ); +void DeleteItemOnIdle( std::unique_ptr<SfxPoolItem> pItem ); #endif |