diff options
author | Noel Grandin <noel@peralex.com> | 2016-06-01 16:22:29 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-06-06 07:01:34 +0000 |
commit | 0323253a7c67316cb96e4a64792ab4fe74aac1ca (patch) | |
tree | 81787c4ae44ff778aa41e12574cd60a624c9277b /sc/source | |
parent | 4d666f5092d7c4f2ece9702dda4d874e44cdc6f7 (diff) |
remove some manual ref-counting
triggered when I noticed a class doing acquire() in the
constructor and then release() in the destructor.
found mostly by
git grep -n -B5 -e '->release()'
Change-Id: I96e43a3d30ffd9ae9a34275f24cd914d8f7b026f
Reviewed-on: https://gerrit.libreoffice.org/25806
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/core/data/dptabsrc.cxx | 35 | ||||
-rw-r--r-- | sc/source/ui/drawfunc/drtxtob.cxx | 16 | ||||
-rw-r--r-- | sc/source/ui/inc/drtxtob.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/inc/editsh.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/unoobj/datauno.cxx | 46 | ||||
-rw-r--r-- | sc/source/ui/view/editsh.cxx | 16 |
6 files changed, 41 insertions, 76 deletions
diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx index c652cf2af303..ce48a82446cb 100644 --- a/sc/source/core/data/dptabsrc.cxx +++ b/sc/source/core/data/dptabsrc.cxx @@ -1333,7 +1333,6 @@ ScDPDimension* ScDPDimensions::getByIndex(long nIndex) const ScDPDimension::ScDPDimension( ScDPSource* pSrc, long nD ) : pSource( pSrc ), nDim( nD ), - pHierarchies( nullptr ), nUsedHier( 0 ), nFunction( SUBTOTAL_FUNC_SUM ), // sum is default mpLayoutName(nullptr), @@ -1350,20 +1349,16 @@ ScDPDimension::~ScDPDimension() { //TODO: release pSource - if ( pHierarchies ) - pHierarchies->release(); // ref-counted - delete pSelectedData; } ScDPHierarchies* ScDPDimension::GetHierarchiesObject() { - if (!pHierarchies) + if (!mxHierarchies.is()) { - pHierarchies = new ScDPHierarchies( pSource, nDim ); - pHierarchies->acquire(); // ref-counted + mxHierarchies = new ScDPHierarchies( pSource, nDim ); } - return pHierarchies; + return mxHierarchies.get(); } const OUString* ScDPDimension::GetLayoutName() const @@ -1790,8 +1785,7 @@ ScDPHierarchy* ScDPHierarchies::getByIndex(long nIndex) const ScDPHierarchy::ScDPHierarchy( ScDPSource* pSrc, long nD, long nH ) : pSource( pSrc ), nDim( nD ), - nHier( nH ), - pLevels( nullptr ) + nHier( nH ) { //TODO: hold pSource } @@ -1799,19 +1793,15 @@ ScDPHierarchy::ScDPHierarchy( ScDPSource* pSrc, long nD, long nH ) : ScDPHierarchy::~ScDPHierarchy() { //TODO: release pSource - - if (pLevels) - pLevels->release(); // ref-counted } ScDPLevels* ScDPHierarchy::GetLevelsObject() { - if (!pLevels) + if (!mxLevels.is()) { - pLevels = new ScDPLevels( pSource, nDim, nHier ); - pLevels->acquire(); // ref-counted + mxLevels = new ScDPLevels( pSource, nDim, nHier ); } - return pLevels; + return mxLevels.get(); } uno::Reference<container::XNameAccess> SAL_CALL ScDPHierarchy::getLevels() @@ -1997,7 +1987,6 @@ ScDPLevel::ScDPLevel( ScDPSource* pSrc, long nD, long nH, long nL ) : nDim( nD ), nHier( nH ), nLev( nL ), - pMembers( nullptr ), aSortInfo( EMPTY_OUSTRING, true, sheet::DataPilotFieldSortMode::NAME ), // default: sort by name nSortMeasure( 0 ), nAutoMeasure( 0 ), @@ -2012,9 +2001,6 @@ ScDPLevel::ScDPLevel( ScDPSource* pSrc, long nD, long nH, long nL ) : ScDPLevel::~ScDPLevel() { //TODO: release pSource - - if ( pMembers ) - pMembers->release(); // ref-counted } void ScDPLevel::EvaluateSortOrder() @@ -2081,12 +2067,11 @@ void ScDPLevel::SetEnableLayout(bool bSet) ScDPMembers* ScDPLevel::GetMembersObject() { - if (!pMembers) + if (!mxMembers.is()) { - pMembers = new ScDPMembers( pSource, nDim, nHier, nLev ); - pMembers->acquire(); // ref-counted + mxMembers = new ScDPMembers( pSource, nDim, nHier, nLev ); } - return pMembers; + return mxMembers.get(); } uno::Reference<container::XNameAccess> SAL_CALL ScDPLevel::getMembers() throw(uno::RuntimeException, std::exception) diff --git a/sc/source/ui/drawfunc/drtxtob.cxx b/sc/source/ui/drawfunc/drtxtob.cxx index ee4d1ec01480..2709e613240b 100644 --- a/sc/source/ui/drawfunc/drtxtob.cxx +++ b/sc/source/ui/drawfunc/drtxtob.cxx @@ -113,7 +113,6 @@ void ScDrawTextObjectBar::StateDisableItems( SfxItemSet &rSet ) ScDrawTextObjectBar::ScDrawTextObjectBar(ScViewData* pData) : SfxShell(pData->GetViewShell()), pViewData(pData), - pClipEvtLstnr(nullptr), bPastePossible(false) { SetPool( pViewData->GetScDrawView()->GetDefaultAttr().GetPool() ); @@ -133,15 +132,13 @@ ScDrawTextObjectBar::ScDrawTextObjectBar(ScViewData* pData) : ScDrawTextObjectBar::~ScDrawTextObjectBar() { - if ( pClipEvtLstnr ) + if ( mxClipEvtLstnr.is() ) { - pClipEvtLstnr->AddRemoveListener( pViewData->GetActiveWin(), false ); + mxClipEvtLstnr->AddRemoveListener( pViewData->GetActiveWin(), false ); // The listener may just now be waiting for the SolarMutex and call the link // afterwards, in spite of RemoveListener. So the link has to be reset, too. - pClipEvtLstnr->ClearCallbackLink(); - - pClipEvtLstnr->release(); + mxClipEvtLstnr->ClearCallbackLink(); } } @@ -492,13 +489,12 @@ void ScDrawTextObjectBar::GetClipState( SfxItemSet& rSet ) return; } - if ( !pClipEvtLstnr ) + if ( !mxClipEvtLstnr.is() ) { // create listener - pClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScDrawTextObjectBar, ClipboardChanged ) ); - pClipEvtLstnr->acquire(); + mxClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScDrawTextObjectBar, ClipboardChanged ) ); vcl::Window* pWin = pViewData->GetActiveWin(); - pClipEvtLstnr->AddRemoveListener( pWin, true ); + mxClipEvtLstnr->AddRemoveListener( pWin, true ); // get initial state TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) ); diff --git a/sc/source/ui/inc/drtxtob.hxx b/sc/source/ui/inc/drtxtob.hxx index 09c1d94d4bfa..5bd5c362386c 100644 --- a/sc/source/ui/inc/drtxtob.hxx +++ b/sc/source/ui/inc/drtxtob.hxx @@ -35,7 +35,7 @@ class TransferableClipboardListener; class ScDrawTextObjectBar : public SfxShell { ScViewData* pViewData; - TransferableClipboardListener* pClipEvtLstnr; + rtl::Reference<TransferableClipboardListener> mxClipEvtLstnr; bool bPastePossible; DECL_LINK_TYPED( ClipboardChanged, TransferableDataHelper*, void ); diff --git a/sc/source/ui/inc/editsh.hxx b/sc/source/ui/inc/editsh.hxx index 85d5fdfc1ccf..037268746b63 100644 --- a/sc/source/ui/inc/editsh.hxx +++ b/sc/source/ui/inc/editsh.hxx @@ -39,7 +39,7 @@ class ScEditShell : public SfxShell private: EditView* pEditView; ScViewData* pViewData; - TransferableClipboardListener* pClipEvtLstnr; + rtl::Reference<TransferableClipboardListener> mxClipEvtLstnr; bool bPastePossible; bool bIsInsertMode; diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx index bad58331f6a6..dc3f64485b30 100644 --- a/sc/source/ui/unoobj/datauno.cxx +++ b/sc/source/ui/unoobj/datauno.cxx @@ -806,28 +806,24 @@ void ScSubTotalDescriptor::SetParam( const ScSubTotalParam& rNew ) } ScRangeSubTotalDescriptor::ScRangeSubTotalDescriptor(ScDatabaseRangeObj* pPar) : - pParent(pPar) + mxParent(pPar) { - if (pParent) - pParent->acquire(); } ScRangeSubTotalDescriptor::~ScRangeSubTotalDescriptor() { - if (pParent) - pParent->release(); } void ScRangeSubTotalDescriptor::GetData( ScSubTotalParam& rParam ) const { - if (pParent) - pParent->GetSubTotalParam( rParam ); + if (mxParent.is()) + mxParent->GetSubTotalParam( rParam ); } void ScRangeSubTotalDescriptor::PutData( const ScSubTotalParam& rParam ) { - if (pParent) - pParent->SetSubTotalParam( rParam ); + if (mxParent.is()) + mxParent->SetSubTotalParam( rParam ); } ScConsolidationDescriptor::ScConsolidationDescriptor() @@ -1544,49 +1540,41 @@ void ScFilterDescriptor::SetParam( const ScQueryParam& rNew ) ScRangeFilterDescriptor::ScRangeFilterDescriptor(ScDocShell* pDocShell, ScDatabaseRangeObj* pPar) : ScFilterDescriptorBase(pDocShell), - pParent(pPar) + mxParent(pPar) { - if (pParent) - pParent->acquire(); } ScRangeFilterDescriptor::~ScRangeFilterDescriptor() { - if (pParent) - pParent->release(); } void ScRangeFilterDescriptor::GetData( ScQueryParam& rParam ) const { - if (pParent) - pParent->GetQueryParam( rParam ); + if (mxParent.is()) + mxParent->GetQueryParam( rParam ); } void ScRangeFilterDescriptor::PutData( const ScQueryParam& rParam ) { - if (pParent) - pParent->SetQueryParam( rParam ); + if (mxParent.is()) + mxParent->SetQueryParam( rParam ); } ScDataPilotFilterDescriptor::ScDataPilotFilterDescriptor(ScDocShell* pDocShell, ScDataPilotDescriptorBase* pPar) : ScFilterDescriptorBase(pDocShell), - pParent(pPar) + mxParent(pPar) { - if (pParent) - pParent->acquire(); } ScDataPilotFilterDescriptor::~ScDataPilotFilterDescriptor() { - if (pParent) - pParent->release(); } void ScDataPilotFilterDescriptor::GetData( ScQueryParam& rParam ) const { - if (pParent) + if (mxParent.is()) { - ScDPObject* pDPObj = pParent->GetDPObject(); + ScDPObject* pDPObj = mxParent->GetDPObject(); if (pDPObj && pDPObj->IsSheetData()) rParam = pDPObj->GetSheetDesc()->GetQueryParam(); } @@ -1594,17 +1582,17 @@ void ScDataPilotFilterDescriptor::GetData( ScQueryParam& rParam ) const void ScDataPilotFilterDescriptor::PutData( const ScQueryParam& rParam ) { - if (pParent) + if (mxParent.is()) { - ScDPObject* pDPObj = pParent->GetDPObject(); + ScDPObject* pDPObj = mxParent->GetDPObject(); if (pDPObj) { - ScSheetSourceDesc aSheetDesc(&pParent->GetDocShell()->GetDocument()); + ScSheetSourceDesc aSheetDesc(&mxParent->GetDocShell()->GetDocument()); if (pDPObj->IsSheetData()) aSheetDesc = *pDPObj->GetSheetDesc(); aSheetDesc.SetQueryParam(rParam); pDPObj->SetSheetDesc(aSheetDesc); - pParent->SetDPObject(pDPObj); + mxParent->SetDPObject(pDPObj); } } } diff --git a/sc/source/ui/view/editsh.cxx b/sc/source/ui/view/editsh.cxx index 92f211e13d71..622989308f44 100644 --- a/sc/source/ui/view/editsh.cxx +++ b/sc/source/ui/view/editsh.cxx @@ -93,7 +93,6 @@ void ScEditShell::InitInterface_Impl() ScEditShell::ScEditShell(EditView* pView, ScViewData* pData) : pEditView (pView), pViewData (pData), - pClipEvtLstnr (nullptr), bPastePossible (false), bIsInsertMode (true) { @@ -105,15 +104,13 @@ ScEditShell::ScEditShell(EditView* pView, ScViewData* pData) : ScEditShell::~ScEditShell() { - if ( pClipEvtLstnr ) + if ( mxClipEvtLstnr.is() ) { - pClipEvtLstnr->AddRemoveListener( pViewData->GetActiveWin(), false ); + mxClipEvtLstnr->AddRemoveListener( pViewData->GetActiveWin(), false ); // The listener may just now be waiting for the SolarMutex and call the link // afterwards, in spite of RemoveListener. So the link has to be reset, too. - pClipEvtLstnr->ClearCallbackLink(); - - pClipEvtLstnr->release(); + mxClipEvtLstnr->ClearCallbackLink(); } } @@ -809,13 +806,12 @@ IMPL_LINK_TYPED( ScEditShell, ClipboardChanged, TransferableDataHelper*, pDataHe void ScEditShell::GetClipState( SfxItemSet& rSet ) { - if ( !pClipEvtLstnr ) + if ( !mxClipEvtLstnr.is() ) { // create listener - pClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScEditShell, ClipboardChanged ) ); - pClipEvtLstnr->acquire(); + mxClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScEditShell, ClipboardChanged ) ); vcl::Window* pWin = pViewData->GetActiveWin(); - pClipEvtLstnr->AddRemoveListener( pWin, true ); + mxClipEvtLstnr->AddRemoveListener( pWin, true ); // get initial state TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) ); |