sw/source/uibase/config/uinums.cxx | 29 +++++++++++------------------ sw/source/uibase/inc/uinums.hxx | 6 +++--- vcl/inc/sallayout.hxx | 3 ++- vcl/source/gdi/sallayout.cxx | 10 ++++------ 4 files changed, 20 insertions(+), 28 deletions(-)
New commits: commit 54604f01330063635fb974b0ab4335d6af851551 Author: Noel Grandin <noel.gran...@collabora.co.uk> Date: Thu Nov 16 09:51:25 2017 +0200 loplugin:useuniqueptr in SwNumRulesWithName Change-Id: If539e9a3d859cea034d53690fdad746479a9f548 Reviewed-on: https://gerrit.libreoffice.org/44820 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/uibase/config/uinums.cxx b/sw/source/uibase/config/uinums.cxx index 24c79ddc2c79..3b7f3e35e10c 100644 --- a/sw/source/uibase/config/uinums.cxx +++ b/sw/source/uibase/config/uinums.cxx @@ -73,14 +73,12 @@ void SwChapterNumRules::Save() SwChapterNumRules::~SwChapterNumRules() { - for(SwNumRulesWithName* pNumRule : pNumRules) - delete pNumRule; } void SwChapterNumRules::Init() { - for(SwNumRulesWithName* & rpNumRule : pNumRules) - rpNumRule = nullptr; + for(auto & rpNumRule : pNumRules) + rpNumRule.reset(); OUString sNm(CHAPTER_FILENAME); SvtPathOptions aOpt; @@ -96,14 +94,14 @@ void SwChapterNumRules::CreateEmptyNumRule(sal_uInt16 const nIndex) { assert(nIndex < nMaxRules); assert(!pNumRules[nIndex]); - pNumRules[nIndex] = new SwNumRulesWithName; + pNumRules[nIndex].reset(new SwNumRulesWithName); } void SwChapterNumRules::ApplyNumRules(const SwNumRulesWithName &rCopy, sal_uInt16 nIdx) { assert(nIdx < nMaxRules); if( !pNumRules[nIdx] ) - pNumRules[nIdx] = new SwNumRulesWithName( rCopy ); + pNumRules[nIdx].reset(new SwNumRulesWithName( rCopy )); else *pNumRules[nIdx] = rCopy; Save(); // store it immediately @@ -117,9 +115,9 @@ SwNumRulesWithName::SwNumRulesWithName( const SwNumRule &rCopy, { const SwNumFormat* pFormat = rCopy.GetNumFormat( n ); if( pFormat ) - aFormats[ n ] = new SwNumFormatGlobal( *pFormat ); + aFormats[ n ].reset(new SwNumFormatGlobal( *pFormat )); else - aFormats[ n ] = nullptr; + aFormats[ n ].reset(); } } @@ -136,8 +134,6 @@ SwNumRulesWithName::SwNumRulesWithName( const SwNumRulesWithName& rCopy ) SwNumRulesWithName::~SwNumRulesWithName() { - for(SwNumFormatGlobal* p : aFormats) - delete p; } SwNumRulesWithName& SwNumRulesWithName::operator=(const SwNumRulesWithName &rCopy) @@ -147,13 +143,11 @@ SwNumRulesWithName& SwNumRulesWithName::operator=(const SwNumRulesWithName &rCop maName = rCopy.maName; for( int n = 0; n < MAXLEVEL; ++n ) { - delete aFormats[ n ]; - - SwNumFormatGlobal* pFormat = rCopy.aFormats[ n ]; + SwNumFormatGlobal* pFormat = rCopy.aFormats[ n ].get(); if( pFormat ) - aFormats[ n ] = new SwNumFormatGlobal( *pFormat ); + aFormats[ n ].reset(new SwNumFormatGlobal( *pFormat )); else - aFormats[ n ] = nullptr; + aFormats[ n ].reset(); } } return *this; @@ -166,7 +160,7 @@ SwNumRule* SwNumRulesWithName::MakeNumRule(SwWrtShell& rSh) const pChg->SetAutoRule( false ); for (sal_uInt16 n = 0; n < MAXLEVEL; ++n) { - SwNumFormatGlobal* pFormat = aFormats[ n ]; + SwNumFormatGlobal* pFormat = aFormats[ n ].get(); if (!pFormat) continue; pChg->Set(n, pFormat->MakeNumFormat(rSh)); @@ -184,8 +178,7 @@ void SwNumRulesWithName::GetNumFormat( void SwNumRulesWithName::SetNumFormat( size_t const nIndex, SwNumFormat const& rNumFormat, OUString const& rName) { - delete aFormats[nIndex]; - aFormats[nIndex] = new SwNumFormatGlobal(rNumFormat); + aFormats[nIndex].reset( new SwNumFormatGlobal(rNumFormat) ); aFormats[nIndex]->sCharFormatName = rName; aFormats[nIndex]->nCharPoolId = USHRT_MAX; aFormats[nIndex]->m_Items.clear(); diff --git a/sw/source/uibase/inc/uinums.hxx b/sw/source/uibase/inc/uinums.hxx index 9ccbddcae512..3e5767c4d87a 100644 --- a/sw/source/uibase/inc/uinums.hxx +++ b/sw/source/uibase/inc/uinums.hxx @@ -56,7 +56,7 @@ class SW_DLLPUBLIC SwNumRulesWithName final SwNumFormat MakeNumFormat(SwWrtShell& rSh) const; }; - SwNumFormatGlobal* aFormats[ MAXLEVEL ]; + std::unique_ptr<SwNumFormatGlobal> aFormats[ MAXLEVEL ]; friend class sw::StoredChapterNumberingRules; friend class SwChapterNumRules; @@ -82,7 +82,7 @@ class SW_DLLPUBLIC SwChapterNumRules final public: enum { nMaxRules = MAX_NUM_RULES }; // currently 9 defined forms private: - SwNumRulesWithName *pNumRules[ MAX_NUM_RULES ]; + std::unique_ptr<SwNumRulesWithName> pNumRules[ MAX_NUM_RULES ]; void Init(); void Save(); @@ -100,7 +100,7 @@ public: inline const SwNumRulesWithName *SwChapterNumRules::GetRules(sal_uInt16 nIdx) const { assert(nIdx < nMaxRules); - return pNumRules[nIdx]; + return pNumRules[nIdx].get(); } commit ef3a2e634ca81f5fb292f88c4d7eb28d170ce3dd Author: Noel Grandin <noel.gran...@collabora.co.uk> Date: Thu Nov 16 09:51:07 2017 +0200 loplugin:useuniqueptr in MultiSalLayout Change-Id: I57ac9cf988dfccfcb38c69ca9c66c2ad77bbdada Reviewed-on: https://gerrit.libreoffice.org/44819 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/vcl/inc/sallayout.hxx b/vcl/inc/sallayout.hxx index 04d488d45fff..ff008c44dd55 100644 --- a/vcl/inc/sallayout.hxx +++ b/vcl/inc/sallayout.hxx @@ -22,6 +22,7 @@ #include <iostream> #include <list> +#include <memory> #include <vector> #include <basegfx/polygon/b2dpolypolygon.hxx> @@ -243,7 +244,7 @@ private: MultiSalLayout& operator=( const MultiSalLayout& ) = delete; private: - SalLayout* mpLayouts[ MAX_FALLBACK ]; + std::unique_ptr<SalLayout> mpLayouts[ MAX_FALLBACK ]; const PhysicalFontFace* mpFallbackFonts[ MAX_FALLBACK ]; ImplLayoutRuns maFallbackRuns[ MAX_FALLBACK ]; int mnLevel; diff --git a/vcl/source/gdi/sallayout.cxx b/vcl/source/gdi/sallayout.cxx index 6184d18e2ca9..b8957ae14eb3 100644 --- a/vcl/source/gdi/sallayout.cxx +++ b/vcl/source/gdi/sallayout.cxx @@ -1031,7 +1031,7 @@ MultiSalLayout::MultiSalLayout( std::unique_ptr<SalLayout> pBaseLayout ) { //maFallbackRuns[0].Clear(); mpFallbackFonts[ 0 ] = nullptr; - mpLayouts[ 0 ] = pBaseLayout.release(); + mpLayouts[ 0 ] = std::move(pBaseLayout); mnUnitsPerPixel = mpLayouts[ 0 ]->GetUnitsPerPixel(); } @@ -1043,8 +1043,6 @@ void MultiSalLayout::SetIncomplete(bool bIncomplete) MultiSalLayout::~MultiSalLayout() { - for( int i = 0; i < mnLevel; ++i ) - delete mpLayouts[ i ]; } void MultiSalLayout::AddFallback( std::unique_ptr<SalLayout> pFallback, @@ -1054,7 +1052,7 @@ void MultiSalLayout::AddFallback( std::unique_ptr<SalLayout> pFallback, return; mpFallbackFonts[ mnLevel ] = pFallbackFont; - mpLayouts[ mnLevel ] = pFallback.release(); + mpLayouts[ mnLevel ] = std::move(pFallback); maFallbackRuns[ mnLevel-1 ] = rFallbackRuns; ++mnLevel; } @@ -1187,14 +1185,14 @@ void MultiSalLayout::AdjustLayout( ImplLayoutArgs& rArgs ) if( (n > 0) && !nValid[ nLevel ] ) { // an empty fallback layout can be released - delete mpLayouts[n]; + mpLayouts[n].reset(); } else { // reshuffle used fallbacks if needed if( nLevel != n ) { - mpLayouts[ nLevel ] = mpLayouts[ n ]; + mpLayouts[ nLevel ] = std::move(mpLayouts[ n ]); mpFallbackFonts[ nLevel ] = mpFallbackFonts[ n ]; maFallbackRuns[ nLevel ] = maFallbackRuns[ n ]; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits