sw/source/core/doc/swstylemanager.cxx | 27 +++++++++++---------------- sw/source/core/text/pormulti.cxx | 13 ++++++------- sw/source/core/text/portxt.cxx | 6 +++--- sw/source/core/text/txttab.cxx | 8 ++++---- 4 files changed, 24 insertions(+), 30 deletions(-)
New commits: commit 9a3cde8f2ad603cf0c57eab66276dea977b20de8 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Thu Aug 18 22:04:19 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Aug 19 10:12:00 2022 +0200 no need to allocate these separately in SwStyleManager Change-Id: Id2ff4612506861a11b03cd0ab458400c7e278c73 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138505 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/core/doc/swstylemanager.cxx b/sw/source/core/doc/swstylemanager.cxx index eec167202e2d..38f79d679af3 100644 --- a/sw/source/core/doc/swstylemanager.cxx +++ b/sw/source/core/doc/swstylemanager.cxx @@ -37,6 +37,7 @@ public: { mMap[ StylePool::nameOf(pStyle) ] = pStyle; } void addCompletePool( StylePool& rPool ); std::shared_ptr<SfxItemSet> getByName( const OUString& rName ) { return mMap[rName]; } + void clear() { mMap.clear(); } }; } @@ -59,8 +60,8 @@ class SwStyleManager : public IStyleAccess { StylePool m_aAutoCharPool; StylePool m_aAutoParaPool; - std::unique_ptr<SwStyleCache> mpCharCache; - std::unique_ptr<SwStyleCache> mpParaCache; + SwStyleCache maCharCache; + SwStyleCache maParaCache; public: // accept empty item set for ignorable paragraph items. @@ -88,8 +89,8 @@ std::unique_ptr<IStyleAccess> createStyleManager( SfxItemSet const * pIgnorableP void SwStyleManager::clearCaches() { - mpCharCache.reset(); - mpParaCache.reset(); + maCharCache.clear(); + maParaCache.clear(); } std::shared_ptr<SfxItemSet> SwStyleManager::getAutomaticStyle( const SfxItemSet& rSet, @@ -109,15 +110,11 @@ std::shared_ptr<SfxItemSet> SwStyleManager::cacheAutomaticStyle( const SfxItemSe std::shared_ptr<SfxItemSet> pStyle = rAutoPool.insertItemSet( rSet ); if (eFamily == IStyleAccess::AUTO_STYLE_CHAR) { - if (!mpCharCache) - mpCharCache.reset(new SwStyleCache()); - mpCharCache->addStyleName( pStyle ); + maCharCache.addStyleName( pStyle ); } else { - if (!mpParaCache) - mpParaCache.reset(new SwStyleCache()); - mpParaCache->addStyleName( pStyle ); + maParaCache.addStyleName( pStyle ); } return pStyle; } @@ -127,17 +124,15 @@ std::shared_ptr<SfxItemSet> SwStyleManager::getByName( const OUString& rName, { StylePool& rAutoPool = eFamily == IStyleAccess::AUTO_STYLE_CHAR ? m_aAutoCharPool : m_aAutoParaPool; - std::unique_ptr<SwStyleCache> &rpCache = eFamily == IStyleAccess::AUTO_STYLE_CHAR ? mpCharCache : mpParaCache; - if( !rpCache ) - rpCache.reset(new SwStyleCache()); - std::shared_ptr<SfxItemSet> pStyle = rpCache->getByName( rName ); + SwStyleCache &rCache = eFamily == IStyleAccess::AUTO_STYLE_CHAR ? maCharCache : maParaCache; + std::shared_ptr<SfxItemSet> pStyle = rCache.getByName( rName ); if( !pStyle ) { // Ok, ok, it's allowed to ask for uncached styles (from UNO) but it should not be done // during loading a document OSL_FAIL( "Don't ask for uncached styles" ); - rpCache->addCompletePool( rAutoPool ); - pStyle = rpCache->getByName( rName ); + rCache.addCompletePool( rAutoPool ); + pStyle = rCache.getByName( rName ); } return pStyle; } commit 7d1b8ae00edc4510d754147aa2b3381accd0fa38 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Thu Aug 18 21:50:15 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Aug 19 10:11:44 2022 +0200 unique_ptr->optional in SwFontSave Change-Id: I57acbc3f43eed6db49e475377b18c0c497acc8c0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138504 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/core/text/pormulti.cxx b/sw/source/core/text/pormulti.cxx index 3fb6a3091ad0..8ca4b9c625ef 100644 --- a/sw/source/core/text/pormulti.cxx +++ b/sw/source/core/text/pormulti.cxx @@ -1572,7 +1572,7 @@ void SwTextPainter::PaintMultiPortion( const SwRect &rPaint, SwSpaceManipulator aManip( GetInfo(), rMulti ); - std::unique_ptr<SwFontSave> pFontSave; + std::optional<SwFontSave> oFontSave; std::unique_ptr<SwFont> pTmpFnt; if( rMulti.IsDouble() ) @@ -1583,11 +1583,10 @@ void SwTextPainter::PaintMultiPortion( const SwRect &rPaint, SetPropFont( 50 ); pTmpFnt->SetProportion( GetPropFont() ); } - pFontSave.reset(new SwFontSave( GetInfo(), pTmpFnt.get(), this )); + oFontSave.emplace( GetInfo(), pTmpFnt.get(), this ); } else { - pFontSave = nullptr; pTmpFnt = nullptr; } @@ -1843,7 +1842,7 @@ void SwTextPainter::PaintMultiPortion( const SwRect &rPaint, // Restore the saved values GetInfo().X( nOldX ); GetInfo().SetLen( nOldLen ); - pFontSave.reset(); + oFontSave.reset(); pTmpFnt.reset(); SetPropFont( 0 ); } @@ -1913,7 +1912,7 @@ bool SwTextFormatter::BuildMultiPortion( SwTextFormatInfo &rInf, } SeekAndChg( rInf ); - std::unique_ptr<SwFontSave> xFontSave; + std::optional<SwFontSave> oFontSave; std::unique_ptr<SwFont> xTmpFont; if( rMulti.IsDouble() ) { @@ -1923,7 +1922,7 @@ bool SwTextFormatter::BuildMultiPortion( SwTextFormatInfo &rInf, SetPropFont( 50 ); xTmpFont->SetProportion( GetPropFont() ); } - xFontSave.reset(new SwFontSave(rInf, xTmpFont.get(), this)); + oFontSave.emplace(rInf, xTmpFont.get(), this); } SwLayoutModeModifier aLayoutModeModifier( *GetInfo().GetOut() ); @@ -2370,7 +2369,7 @@ bool SwTextFormatter::BuildMultiPortion( SwTextFormatInfo &rInf, SeekAndChg( rInf ); delete pFirstRest; delete pSecondRest; - xFontSave.reset(); + oFontSave.reset(); return bRet; } diff --git a/sw/source/core/text/portxt.cxx b/sw/source/core/text/portxt.cxx index 09a2fc2c0b67..77aa7676e1f3 100644 --- a/sw/source/core/text/portxt.cxx +++ b/sw/source/core/text/portxt.cxx @@ -789,7 +789,7 @@ void SwHolePortion::Paint( const SwTextPaintInfo &rInf ) const // #i68503# the hole must have no decoration for a consistent visual appearance const SwFont* pOrigFont = rInf.GetFont(); std::unique_ptr<SwFont> pHoleFont; - std::unique_ptr<SwFontSave> pFontSave; + std::optional<SwFontSave> oFontSave; if( pOrigFont->GetUnderline() != LINESTYLE_NONE || pOrigFont->GetOverline() != LINESTYLE_NONE || pOrigFont->GetStrikeout() != STRIKEOUT_NONE ) @@ -798,7 +798,7 @@ void SwHolePortion::Paint( const SwTextPaintInfo &rInf ) const pHoleFont->SetUnderline( LINESTYLE_NONE ); pHoleFont->SetOverline( LINESTYLE_NONE ); pHoleFont->SetStrikeout( STRIKEOUT_NONE ); - pFontSave.reset(new SwFontSave( rInf, pHoleFont.get() )); + oFontSave.emplace( rInf, pHoleFont.get() ); } if (bPDFExport) @@ -812,7 +812,7 @@ void SwHolePortion::Paint( const SwTextPaintInfo &rInf ) const rInf.DrawText(*this, rInf.GetLen()); } - pFontSave.reset(); + oFontSave.reset(); pHoleFont.reset(); } diff --git a/sw/source/core/text/txttab.cxx b/sw/source/core/text/txttab.cxx index 82f8e3129c97..aa0ac928833e 100644 --- a/sw/source/core/text/txttab.cxx +++ b/sw/source/core/text/txttab.cxx @@ -374,14 +374,14 @@ bool SwTabPortion::PreFormat( SwTextFormatInfo &rInf ) // #i89179# // tab portion representing the list tab of a list label gets the // same font as the corresponding number portion - std::unique_ptr< SwFontSave > pSave; + std::optional< SwFontSave > oSave; if ( GetLen() == TextFrameIndex(0) && rInf.GetLast() && rInf.GetLast()->InNumberGrp() && static_cast<SwNumberPortion*>(rInf.GetLast())->HasFont() ) { const SwFont* pNumberPortionFont = static_cast<SwNumberPortion*>(rInf.GetLast())->GetFont(); - pSave.reset( new SwFontSave( rInf, const_cast<SwFont*>(pNumberPortionFont) ) ); + oSave.emplace( rInf, const_cast<SwFont*>(pNumberPortionFont) ); } OUString aTmp( ' ' ); SwTextSizeInfo aInf( rInf, &aTmp ); @@ -575,7 +575,7 @@ void SwTabPortion::Paint( const SwTextPaintInfo &rInf ) const // #i89179# // tab portion representing the list tab of a list label gets the // same font as the corresponding number portion - std::unique_ptr< SwFontSave > pSave; + std::optional< SwFontSave > oSave; bool bAfterNumbering = false; if (GetLen() == TextFrameIndex(0)) { @@ -587,7 +587,7 @@ void SwTabPortion::Paint( const SwTextPaintInfo &rInf ) const { const SwFont* pNumberPortionFont = static_cast<const SwNumberPortion*>(pPrevPortion)->GetFont(); - pSave.reset( new SwFontSave( rInf, const_cast<SwFont*>(pNumberPortionFont) ) ); + oSave.emplace( rInf, const_cast<SwFont*>(pNumberPortionFont) ); bAfterNumbering = true; } }