Kaydet (Commit) 06765e45 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in DeleteItemOnIdle

Change-Id: I6a72417bcab1ac48b5d8a73005104c8627dde32b
Reviewed-on: https://gerrit.libreoffice.org/59349
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 1188bebb
......@@ -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;
......
......@@ -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
}
......
......@@ -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();
}
......
......@@ -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)
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment