diff options
author | Noel Grandin <noel@peralex.com> | 2016-06-07 09:03:53 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-06-08 06:39:11 +0000 |
commit | e626ebf50884520b38137a52a6ffc654c377956d (patch) | |
tree | cd38bee6f815381dfcecb88543708f250188a599 /sc | |
parent | 261f734b3c0e62ada51485ba81a535d32049c946 (diff) |
remove some manual refcounting in sc
Change-Id: Ie13b28ffaf861dc85063e5a4b23fef8c929033d9
Reviewed-on: https://gerrit.libreoffice.org/26006
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/dptabsrc.hxx | 2 | ||||
-rw-r--r-- | sc/inc/fmtuno.hxx | 2 | ||||
-rw-r--r-- | sc/inc/notesuno.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/data/dptabsrc.cxx | 17 | ||||
-rw-r--r-- | sc/source/filter/xml/XMLTrackedChangesContext.cxx | 20 | ||||
-rw-r--r-- | sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx | 38 | ||||
-rw-r--r-- | sc/source/ui/inc/AccessibleDocumentPagePreview.hxx | 4 | ||||
-rw-r--r-- | sc/source/ui/unoobj/fmtuno.cxx | 33 | ||||
-rw-r--r-- | sc/source/ui/unoobj/notesuno.cxx | 11 |
9 files changed, 45 insertions, 85 deletions
diff --git a/sc/inc/dptabsrc.hxx b/sc/inc/dptabsrc.hxx index 03039dfbfca5..cbbd28fb9c37 100644 --- a/sc/inc/dptabsrc.hxx +++ b/sc/inc/dptabsrc.hxx @@ -88,7 +88,7 @@ class ScDPSource : public cppu::WeakImplHelper< { private: ScDPTableData* pData; // data source (ScDPObject manages its life time) - ScDPDimensions* pDimensions; // api objects + rtl::Reference<ScDPDimensions> pDimensions; // api objects // settings: std::vector<long> maColDims; diff --git a/sc/inc/fmtuno.hxx b/sc/inc/fmtuno.hxx index 76209ad438f8..774d94ad19bb 100644 --- a/sc/inc/fmtuno.hxx +++ b/sc/inc/fmtuno.hxx @@ -74,7 +74,7 @@ class ScTableConditionalFormat : public cppu::WeakImplHelper< css::lang::XServiceInfo > { private: - std::vector<ScTableConditionalEntry*> aEntries; + std::vector<rtl::Reference<ScTableConditionalEntry>> maEntries; ScTableConditionalEntry* GetObjectByIndex_Impl(sal_uInt16 nIndex) const; void AddEntry_Impl(const ScCondFormatEntryItem& aEntry); diff --git a/sc/inc/notesuno.hxx b/sc/inc/notesuno.hxx index ca9a3f494fb2..5b41cb2a3062 100644 --- a/sc/inc/notesuno.hxx +++ b/sc/inc/notesuno.hxx @@ -27,6 +27,7 @@ #include <com/sun/star/text/XSimpleText.hpp> #include <cppuhelper/implbase.hxx> #include <svl/lstner.hxx> +#include <rtl/ref.hxx> #include "address.hxx" class ScDocShell; @@ -118,7 +119,7 @@ private: private: ScDocShell* pDocShell; ScAddress aCellPos; - SvxUnoText* pUnoText; + rtl::Reference<SvxUnoText> pUnoText; }; #endif diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx index c92c4e212a86..b57261420e6b 100644 --- a/sc/source/core/data/dptabsrc.cxx +++ b/sc/source/core/data/dptabsrc.cxx @@ -92,7 +92,6 @@ static bool lcl_GetBoolFromAny( const uno::Any& aAny ) ScDPSource::ScDPSource( ScDPTableData* pD ) : pData( pD ), - pDimensions( nullptr ), bColumnGrand( true ), // default is true bRowGrand( true ), bIgnoreEmptyRows( false ), @@ -111,9 +110,6 @@ ScDPSource::ScDPSource( ScDPTableData* pD ) : ScDPSource::~ScDPSource() { - if (pDimensions) - pDimensions->release(); // ref-counted - // free lists delete[] pColResults; @@ -299,12 +295,11 @@ bool ScDPSource::IsDateDimension(long nDim) ScDPDimensions* ScDPSource::GetDimensionsObject() { - if (!pDimensions) + if (!pDimensions.is()) { pDimensions = new ScDPDimensions(this); - pDimensions->acquire(); // ref-counted } - return pDimensions; + return pDimensions.get(); } uno::Reference<container::XNameAccess> SAL_CALL ScDPSource::getDimensions() throw(uno::RuntimeException, std::exception) @@ -319,7 +314,7 @@ void ScDPSource::SetDupCount( long nNew ) ScDPDimension* ScDPSource::AddDuplicated(long /* nSource */, const OUString& rNewName) { - OSL_ENSURE( pDimensions, "AddDuplicated without dimensions?" ); + OSL_ENSURE( pDimensions.is(), "AddDuplicated without dimensions?" ); // re-use @@ -539,11 +534,7 @@ void ScDPSource::disposeData() aRowLevelList.clear(); } - if ( pDimensions ) - { - pDimensions->release(); // ref-counted - pDimensions = nullptr; // settings have to be applied (from SaveData) again! - } + pDimensions.clear(); // settings have to be applied (from SaveData) again! SetDupCount( 0 ); maColDims.clear(); diff --git a/sc/source/filter/xml/XMLTrackedChangesContext.cxx b/sc/source/filter/xml/XMLTrackedChangesContext.cxx index ac36be357e38..6c56b0fc22ec 100644 --- a/sc/source/filter/xml/XMLTrackedChangesContext.cxx +++ b/sc/source/filter/xml/XMLTrackedChangesContext.cxx @@ -228,7 +228,7 @@ class ScXMLChangeCellContext : public SvXMLImportContext OUString sText; OUString& rInputString; - ScEditEngineTextObj* pEditTextObj; + rtl::Reference<ScEditEngineTextObj> mpEditTextObj; double& rDateTimeValue; double fValue; sal_uInt16& rType; @@ -254,7 +254,7 @@ public: const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override; void CreateTextPContext(bool bIsNewParagraph); - bool IsEditCell() { return pEditTextObj != nullptr; } + bool IsEditCell() { return mpEditTextObj.is(); } void SetText(const OUString& sTempText) { sText = sTempText; } virtual void EndElement() override; @@ -1012,7 +1012,6 @@ ScXMLChangeCellContext::ScXMLChangeCellContext( ScXMLImport& rImport, : SvXMLImportContext( rImport, nPrfx, rLName ) , mrOldCell(rOldCell) , rInputString(rTempInputString) - , pEditTextObj(nullptr) , rDateTimeValue(fDateTimeValue) , fValue(0.0) , rType(nType) @@ -1122,7 +1121,7 @@ SvXMLImportContext *ScXMLChangeCellContext::CreateChildContext( sal_uInt16 nPref } else { - if (!pEditTextObj) + if (!mpEditTextObj.is()) CreateTextPContext(true); pContext = GetScImport().GetTextImport()->CreateTextChildContext( GetScImport(), nPrefix, rLocalName, xAttrList); @@ -1139,10 +1138,9 @@ void ScXMLChangeCellContext::CreateTextPContext(bool bIsNewParagraph) { if (GetScImport().GetDocument()) { - pEditTextObj = new ScEditEngineTextObj(); - pEditTextObj->acquire(); - pEditTextObj->GetEditEngine()->SetEditTextObjectPool(GetScImport().GetDocument()->GetEditPool()); - uno::Reference <text::XText> xText(pEditTextObj); + mpEditTextObj = new ScEditEngineTextObj(); + mpEditTextObj->GetEditEngine()->SetEditTextObjectPool(GetScImport().GetDocument()->GetEditPool()); + uno::Reference <text::XText> xText(mpEditTextObj.get()); if (xText.is()) { uno::Reference<text::XTextCursor> xTextCursor(xText->createTextCursor()); @@ -1164,7 +1162,7 @@ void ScXMLChangeCellContext::EndElement() if (!bEmpty) { ScDocument* pDoc = GetScImport().GetDocument(); - if (pEditTextObj) + if (mpEditTextObj.is()) { if (GetImport().GetTextImport()->GetCursor().is()) { @@ -1179,9 +1177,9 @@ void ScXMLChangeCellContext::EndElement() // The cell will own the text object instance. mrOldCell.meType = CELLTYPE_EDIT; - mrOldCell.mpEditText = pEditTextObj->CreateTextObject(); + mrOldCell.mpEditText = mpEditTextObj->CreateTextObject(); GetScImport().GetTextImport()->ResetCursor(); - pEditTextObj->release(); + mpEditTextObj.clear(); } else { diff --git a/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx b/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx index 9979338c04cd..4e6aa39d7506 100644 --- a/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx +++ b/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx @@ -1186,9 +1186,7 @@ ScAccessibleDocumentPagePreview::ScAccessibleDocumentPagePreview( ScAccessibleDocumentBase(rxParent), mpViewShell(pViewShell), mpNotesChildren(nullptr), - mpShapeChildren(nullptr), - mpHeader(nullptr), - mpFooter(nullptr) + mpShapeChildren(nullptr) { if (pViewShell) pViewShell->AddAccessibilityObject(*this); @@ -1210,16 +1208,8 @@ void SAL_CALL ScAccessibleDocumentPagePreview::disposing() { SolarMutexGuard aGuard; mpTable.clear(); - if (mpHeader) - { - mpHeader->release(); - mpHeader = nullptr; - } - if (mpFooter) - { - mpFooter->release(); - mpFooter = nullptr; - } + mpHeader.clear(); + mpFooter.clear(); if (mpViewShell) { @@ -1361,29 +1351,27 @@ uno::Reference< XAccessible > SAL_CALL ScAccessibleDocumentPagePreview::getAcces xAccessible = GetNotesChildren()->GetAt(rPoint); if (!xAccessible.is()) { - if (!mpHeader || !mpFooter) + if (!mpHeader.is() || !mpFooter.is()) { const ScPreviewLocationData& rData = mpViewShell->GetLocationData(); ScPagePreviewCountData aCount( rData, mpViewShell->GetWindow(), GetNotesChildren(), GetShapeChildren() ); - if (!mpHeader) + if (!mpHeader.is()) { mpHeader = new ScAccessiblePageHeader( this, mpViewShell, true, aCount.nBackShapes + aCount.nHeaders - 1); - mpHeader->acquire(); } - if (!mpFooter) + if (!mpFooter.is()) { mpFooter = new ScAccessiblePageHeader( this, mpViewShell, false, aCount.nBackShapes + aCount.nHeaders + aCount.nTables + aCount.nNoteParagraphs + aCount.nFooters - 1 ); - mpFooter->acquire(); } } Point aPoint(VCLPoint(rPoint)); if (VCLRectangle(mpHeader->getBounds()).IsInside(aPoint)) - xAccessible = mpHeader; + xAccessible = mpHeader.get(); else if (VCLRectangle(mpFooter->getBounds()).IsInside(aPoint)) - xAccessible = mpFooter; + xAccessible = mpFooter.get(); } if (!xAccessible.is()) xAccessible = GetShapeChildren()->GetBackgroundShapeAt(rPoint); @@ -1444,13 +1432,12 @@ uno::Reference<XAccessible> SAL_CALL ScAccessibleDocumentPagePreview::getAccessi } else if ( nIndex < aCount.nBackShapes + aCount.nHeaders ) { - if ( !mpHeader ) + if ( !mpHeader.is() ) { mpHeader = new ScAccessiblePageHeader( this, mpViewShell, true, nIndex ); - mpHeader->acquire(); } - xAccessible = mpHeader; + xAccessible = mpHeader.get(); } else if ( nIndex < aCount.nBackShapes + aCount.nHeaders + aCount.nTables ) { @@ -1467,12 +1454,11 @@ uno::Reference<XAccessible> SAL_CALL ScAccessibleDocumentPagePreview::getAccessi } else if ( (nIndex < aCount.nBackShapes + aCount.nHeaders + aCount.nTables + aCount.nNoteParagraphs + aCount.nFooters) ) { - if ( !mpFooter ) + if ( !mpFooter.is() ) { mpFooter = new ScAccessiblePageHeader( this, mpViewShell, false, nIndex ); - mpFooter->acquire(); } - xAccessible = mpFooter; + xAccessible = mpFooter.get(); } else { diff --git a/sc/source/ui/inc/AccessibleDocumentPagePreview.hxx b/sc/source/ui/inc/AccessibleDocumentPagePreview.hxx index d72a417d102c..26c6d9d525ab 100644 --- a/sc/source/ui/inc/AccessibleDocumentPagePreview.hxx +++ b/sc/source/ui/inc/AccessibleDocumentPagePreview.hxx @@ -135,8 +135,8 @@ private: ScNotesChildren* mpNotesChildren; ScShapeChildren* mpShapeChildren; rtl::Reference<ScAccessiblePreviewTable> mpTable; - ScAccessiblePageHeader* mpHeader; - ScAccessiblePageHeader* mpFooter; + rtl::Reference<ScAccessiblePageHeader> mpHeader; + rtl::Reference<ScAccessiblePageHeader> mpFooter; bool IsDefunc( const css::uno::Reference<css::accessibility::XAccessibleStateSet>& rxParentStates); diff --git a/sc/source/ui/unoobj/fmtuno.cxx b/sc/source/ui/unoobj/fmtuno.cxx index e4692ae1af9c..417c97bb3900 100644 --- a/sc/source/ui/unoobj/fmtuno.cxx +++ b/sc/source/ui/unoobj/fmtuno.cxx @@ -195,11 +195,10 @@ void ScTableConditionalFormat::FillFormat( ScConditionalFormat& rFormat, OSL_ENSURE( rFormat.IsEmpty(), "FillFormat: Format nicht leer" ); - std::vector<ScTableConditionalEntry*>::const_iterator iter; - for (iter = aEntries.begin(); iter != aEntries.end(); ++iter) + for (const auto & i : maEntries) { ScCondFormatEntryItem aData; - (*iter)->GetData(aData); + i->GetData(aData); FormulaGrammar::Grammar eGrammar1 = lclResolveGrammar( eGrammar, aData.meGrammar1 ); FormulaGrammar::Grammar eGrammar2 = lclResolveGrammar( eGrammar, aData.meGrammar2 ); @@ -229,23 +228,19 @@ void ScTableConditionalFormat::FillFormat( ScConditionalFormat& rFormat, ScTableConditionalFormat::~ScTableConditionalFormat() { - std::for_each(aEntries.begin(), aEntries.end(), - [] (ScTableConditionalEntry *const pEntry) { pEntry->release(); } ); - } void ScTableConditionalFormat::AddEntry_Impl(const ScCondFormatEntryItem& aEntry) { ScTableConditionalEntry* pNew = new ScTableConditionalEntry(aEntry); - pNew->acquire(); - aEntries.push_back(pNew); + maEntries.push_back(pNew); } // XSheetConditionalFormat ScTableConditionalEntry* ScTableConditionalFormat::GetObjectByIndex_Impl(sal_uInt16 nIndex) const { - return nIndex < aEntries.size() ? aEntries[nIndex] : nullptr; + return nIndex < maEntries.size() ? maEntries[nIndex].get() : nullptr; } void SAL_CALL ScTableConditionalFormat::addNew( @@ -349,22 +344,16 @@ void SAL_CALL ScTableConditionalFormat::removeByIndex( sal_Int32 nIndex ) { SolarMutexGuard aGuard; - if (nIndex < static_cast<sal_Int32>(aEntries.size()) && nIndex >= 0) + if (nIndex < static_cast<sal_Int32>(maEntries.size()) && nIndex >= 0) { - std::vector<ScTableConditionalEntry*>::iterator iter = aEntries.begin()+nIndex; - - (*iter)->release(); - aEntries.erase(iter); + maEntries.erase(maEntries.begin()+nIndex); } } void SAL_CALL ScTableConditionalFormat::clear() throw(uno::RuntimeException, std::exception) { SolarMutexGuard aGuard; - std::for_each(aEntries.begin(),aEntries.end(), - [] (ScTableConditionalEntry *const pEntry) { pEntry->release(); } ); - - aEntries.clear(); + maEntries.clear(); } // XEnumerationAccess @@ -381,7 +370,7 @@ uno::Reference<container::XEnumeration> SAL_CALL ScTableConditionalFormat::creat sal_Int32 SAL_CALL ScTableConditionalFormat::getCount() throw(uno::RuntimeException, std::exception) { SolarMutexGuard aGuard; - return aEntries.size(); + return maEntries.size(); } uno::Any SAL_CALL ScTableConditionalFormat::getByIndex( sal_Int32 nIndex ) @@ -425,7 +414,7 @@ uno::Any SAL_CALL ScTableConditionalFormat::getByName( const OUString& aName ) SolarMutexGuard aGuard; uno::Reference<sheet::XSheetConditionalEntry> xEntry; - long nCount = aEntries.size(); + long nCount = maEntries.size(); for (long i=0; i<nCount; i++) if ( aName == lcl_GetEntryNameFromIndex(i) ) { @@ -444,7 +433,7 @@ uno::Sequence<OUString> SAL_CALL ScTableConditionalFormat::getElementNames() { SolarMutexGuard aGuard; - long nCount = aEntries.size(); + long nCount = maEntries.size(); uno::Sequence<OUString> aNames(nCount); OUString* pArray = aNames.getArray(); for (long i=0; i<nCount; i++) @@ -458,7 +447,7 @@ sal_Bool SAL_CALL ScTableConditionalFormat::hasByName( const OUString& aName ) { SolarMutexGuard aGuard; - long nCount = aEntries.size(); + long nCount = maEntries.size(); for (long i=0; i<nCount; i++) if ( aName == lcl_GetEntryNameFromIndex(i) ) return true; diff --git a/sc/source/ui/unoobj/notesuno.cxx b/sc/source/ui/unoobj/notesuno.cxx index ad2f39948878..b6b5c5ff15c5 100644 --- a/sc/source/ui/unoobj/notesuno.cxx +++ b/sc/source/ui/unoobj/notesuno.cxx @@ -57,8 +57,7 @@ SC_SIMPLE_SERVICE_INFO( ScAnnotationObj, "ScAnnotationObj", "com.sun.star.sheet. ScAnnotationObj::ScAnnotationObj(ScDocShell* pDocSh, const ScAddress& rPos) : pDocShell( pDocSh ), - aCellPos( rPos ), - pUnoText( nullptr ) + aCellPos( rPos ) { pDocShell->GetDocument().AddUnoObject(*this); @@ -72,9 +71,6 @@ ScAnnotationObj::~ScAnnotationObj() if (pDocShell) pDocShell->GetDocument().RemoveUnoObject(*this); - - if (pUnoText) - pUnoText->release(); } void ScAnnotationObj::Notify( SfxBroadcaster&, const SfxHint& rHint ) @@ -237,14 +233,13 @@ uno::Reference < drawing::XShape > SAL_CALL ScAnnotationObj::getAnnotationShape( SvxUnoText& ScAnnotationObj::GetUnoText() { - if (!pUnoText) + if (!pUnoText.is()) { ScAnnotationEditSource aEditSource( pDocShell, aCellPos ); pUnoText = new SvxUnoText( &aEditSource, lcl_GetAnnotationPropertySet(), uno::Reference<text::XText>() ); - pUnoText->acquire(); } - return *pUnoText; + return *pUnoText.get(); } const ScPostIt* ScAnnotationObj::ImplGetNote() const |