From 987cd20a33b396aa105b0abbec175b5592486c8f Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 29 Jan 2018 12:13:56 +0200 Subject: [PATCH] loplugin:useuniqueptr in ImpEditEngine Change-Id: I5afc846c803f5191bb5e04590923059e88434b76 Reviewed-on: https://gerrit.libreoffice.org/49176 Tested-by: Jenkins Reviewed-by: Noel Grandin --- compilerplugins/clang/useuniqueptr.cxx | 3 +++ editeng/source/editeng/editeng.cxx | 2 +- editeng/source/editeng/impedit.hxx | 16 +++++++------- editeng/source/editeng/impedit2.cxx | 24 ++++++++++----------- editeng/source/editeng/impedit3.cxx | 30 +++++++++++--------------- editeng/source/editeng/impedit4.cxx | 12 +++++------ 6 files changed, 41 insertions(+), 46 deletions(-) diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx index 655a25fe4325..dfa0917735f0 100644 --- a/compilerplugins/clang/useuniqueptr.cxx +++ b/compilerplugins/clang/useuniqueptr.cxx @@ -213,6 +213,9 @@ void UseUniquePtr::CheckDeleteExpr(const CXXDestructorDecl* destructorDecl, cons // not sure how the node management is working here if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/i18npool/source/localedata/saxparser.cxx")) return; + // has a pointer that it only sometimes owns + if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/editeng/source/editeng/impedit.hxx")) + return; report( DiagnosticsEngine::Warning, diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx index d2531b0f769b..05c0ffa7f2dc 100644 --- a/editeng/source/editeng/editeng.cxx +++ b/editeng/source/editeng/editeng.cxx @@ -523,7 +523,7 @@ void EditEngine::SetPolygon(const basegfx::B2DPolyPolygon& rPolyPolygon, const b } TextRanger* pRanger = new TextRanger( rPolyPolygon, pLinePolyPolygon, 30, 2, 2, bSimple, true ); - pImpEditEngine->SetTextRanger( pRanger ); + pImpEditEngine->SetTextRanger( std::unique_ptr(pRanger) ); pImpEditEngine->SetPaperSize( pRanger->GetBoundRect().GetSize() ); } diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index 1e53e23aa185..1f651ea7f43d 100644 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -436,7 +436,7 @@ private: EditEngine* pEditEngine; ViewsType aEditViews; EditView* pActiveView; - TextRanger* pTextRanger; + std::unique_ptr pTextRanger; SfxStyleSheetPool* pStylePool; SfxItemPool* pTextObjectPool; @@ -446,13 +446,13 @@ private: VclPtr mpOwnDev; svtools::ColorConfig maColorConfig; - mutable SvtCTLOptions* pCTLOptions; + mutable std::unique_ptr pCTLOptions; std::unique_ptr pEmptyItemSet; EditUndoManager* pUndoManager; ESelection* pUndoMarkSelection; - ImplIMEInfos* mpIMEInfos; + std::unique_ptr mpIMEInfos; std::vector aNotifyCache; @@ -474,7 +474,7 @@ private: sal_Int32 nBigTextObjectStart; css::uno::Reference< css::linguistic2::XSpellChecker1 > xSpeller; css::uno::Reference< css::linguistic2::XHyphenator > xHyphenator; - SpellInfo* pSpellInfo; + std::unique_ptr pSpellInfo; mutable css::uno::Reference < css::i18n::XBreakIterator > xBI; mutable css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > xISC; @@ -708,7 +708,7 @@ private: void ImplUpdateOverflowingParaNum( sal_uInt32 ); void ImplUpdateOverflowingLineNum( sal_uInt32, sal_uInt32, sal_uInt32 ); - SpellInfo * CreateSpellInfo( bool bMultipleDocs ); + void CreateSpellInfo( bool bMultipleDocs ); /// Obtains a view shell ID from the active EditView. ViewShellId CreateViewShellId(); @@ -758,8 +758,8 @@ public: sal_uInt8 GetRightToLeft( sal_Int32 nPara, sal_Int32 nChar, sal_Int32* pStart = nullptr, sal_Int32* pEnd = nullptr ); bool HasDifferentRTLLevels( const ContentNode* pNode ); - void SetTextRanger( TextRanger* pRanger ); - TextRanger* GetTextRanger() const { return pTextRanger; } + void SetTextRanger( std::unique_ptr pRanger ); + TextRanger* GetTextRanger() const { return pTextRanger.get(); } const Size& GetMinAutoPaperSize() const { return aMinAutoPaperSize; } void SetMinAutoPaperSize( const Size& rSz ) { aMinAutoPaperSize = rSz; } @@ -942,7 +942,7 @@ public: void GetAllMisspellRanges( std::vector& rRanges ) const; void SetAllMisspellRanges( const std::vector& rRanges ); - SpellInfo* GetSpellInfo() const { return pSpellInfo; } + SpellInfo* GetSpellInfo() const { return pSpellInfo.get(); } void SetDefaultLanguage( LanguageType eLang ) { eDefLanguage = eLang; } LanguageType GetDefaultLanguage() const { return eDefLanguage; } diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index a7e5ef0c9ceb..a72dfd647f3e 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -198,10 +198,10 @@ ImpEditEngine::~ImpEditEngine() // before destroying the ImpEditEngine! assert(!pUndoManager || typeid(*pUndoManager) == typeid(EditUndoManager)); delete pUndoManager; - delete pTextRanger; - delete mpIMEInfos; - delete pCTLOptions; - delete pSpellInfo; + pTextRanger.reset(); + mpIMEInfos.reset(); + pCTLOptions.reset(); + pSpellInfo.reset(); } void ImpEditEngine::SetRefDevice( OutputDevice* pRef ) @@ -359,13 +359,13 @@ void ImpEditEngine::Command( const CommandEvent& rCEvt, EditView* pView ) if ( rCEvt.GetCommand() == CommandEventId::StartExtTextInput ) { pView->DeleteSelected(); - delete mpIMEInfos; + mpIMEInfos.reset(); EditPaM aPaM = pView->GetImpEditView()->GetEditSelection().Max(); OUString aOldTextAfterStartPos = aPaM.GetNode()->Copy( aPaM.GetIndex() ); sal_Int32 nMax = aOldTextAfterStartPos.indexOf( CH_FEATURE ); if ( nMax != -1 ) // don't overwrite features! aOldTextAfterStartPos = aOldTextAfterStartPos.copy( 0, nMax ); - mpIMEInfos = new ImplIMEInfos( aPaM, aOldTextAfterStartPos ); + mpIMEInfos.reset( new ImplIMEInfos( aPaM, aOldTextAfterStartPos ) ); mpIMEInfos->bWasCursorOverwrite = !pView->IsInsertMode(); UndoActionStart( EDITUNDO_INSERT ); } @@ -400,8 +400,7 @@ void ImpEditEngine::Command( const CommandEvent& rCEvt, EditView* pView ) bool bWasCursorOverwrite = mpIMEInfos->bWasCursorOverwrite; - delete mpIMEInfos; - mpIMEInfos = nullptr; + mpIMEInfos.reset(); FormatAndUpdate( pView ); @@ -1590,7 +1589,7 @@ bool ImpEditEngine::IsInputSequenceCheckingRequired( sal_Unicode nChar, const Ed { uno::Reference < i18n::XBreakIterator > _xBI( ImplGetBreakIterator() ); if (!pCTLOptions) - pCTLOptions = new SvtCTLOptions; + pCTLOptions.reset( new SvtCTLOptions ); // get the index that really is first const sal_Int32 nFirstPos = std::min(rCurSel.Min().GetIndex(), rCurSel.Max().GetIndex()); @@ -2616,7 +2615,7 @@ EditPaM ImpEditEngine::InsertTextUserInput( const EditSelection& rCurSel, { uno::Reference < i18n::XExtendedInputSequenceChecker > _xISC( ImplGetInputSequenceChecker() ); if (!pCTLOptions) - pCTLOptions = new SvtCTLOptions; + pCTLOptions.reset( new SvtCTLOptions ); if (_xISC.is() || pCTLOptions) { @@ -3453,8 +3452,7 @@ void ImpEditEngine::SetActiveView( EditView* pView ) if ( !pView && mpIMEInfos ) { - delete mpIMEInfos; - mpIMEInfos = nullptr; + mpIMEInfos.reset(); } } @@ -4355,7 +4353,7 @@ bool ImpEditEngine::IsVisualCursorTravelingEnabled() bool bVisualCursorTravaling = false; if( !pCTLOptions ) - pCTLOptions = new SvtCTLOptions; + pCTLOptions.reset( new SvtCTLOptions ); if ( pCTLOptions->IsCTLFontEnabled() && ( pCTLOptions->GetCTLCursorMovement() == SvtCTLOptions::MOVEMENT_VISUAL ) ) { diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx index f81e1f7fd46e..668b34ab552c 100644 --- a/editeng/source/editeng/impedit3.cxx +++ b/editeng/source/editeng/impedit3.cxx @@ -2610,25 +2610,21 @@ void ImpEditEngine::RecalcTextPortion( ParaPortion* pParaPortion, sal_Int32 nSta #endif } -void ImpEditEngine::SetTextRanger( TextRanger* pRanger ) +void ImpEditEngine::SetTextRanger( std::unique_ptr pRanger ) { - if ( pTextRanger != pRanger ) + pTextRanger = std::move(pRanger); + + for ( sal_Int32 nPara = 0; nPara < GetParaPortions().Count(); nPara++ ) { - delete pTextRanger; - pTextRanger = pRanger; - - for ( sal_Int32 nPara = 0; nPara < GetParaPortions().Count(); nPara++ ) - { - ParaPortion* pParaPortion = GetParaPortions()[nPara]; - pParaPortion->MarkSelectionInvalid( 0 ); - pParaPortion->GetLines().Reset(); - } - - FormatFullDoc(); - UpdateViews( GetActiveView() ); - if ( GetUpdateMode() && GetActiveView() ) - pActiveView->ShowCursor(false, false); + ParaPortion* pParaPortion = GetParaPortions()[nPara]; + pParaPortion->MarkSelectionInvalid( 0 ); + pParaPortion->GetLines().Reset(); } + + FormatFullDoc(); + UpdateViews( GetActiveView() ); + if ( GetUpdateMode() && GetActiveView() ) + pActiveView->ShowCursor(false, false); } void ImpEditEngine::SetVertical( bool bVertical, bool bTopToBottom) @@ -4353,7 +4349,7 @@ LanguageType ImpEditEngine::ImplCalcDigitLang(LanguageType eCurLang) const // #114278# Also setting up digit language from Svt options // (cannot reliably inherit the outdev's setting) if( !pCTLOptions ) - pCTLOptions = new SvtCTLOptions; + pCTLOptions.reset( new SvtCTLOptions ); LanguageType eLang = eCurLang; const SvtCTLOptions::TextNumerals nCTLTextNumerals = pCTLOptions->GetCTLTextNumerals(); diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index 06e07e849cd4..2a995e8eb307 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -1426,10 +1426,10 @@ Reference< XSpellChecker1 > const & ImpEditEngine::GetSpeller() } -SpellInfo * ImpEditEngine::CreateSpellInfo( bool bMultipleDocs ) +void ImpEditEngine::CreateSpellInfo( bool bMultipleDocs ) { if (!pSpellInfo) - pSpellInfo = new SpellInfo; + pSpellInfo.reset( new SpellInfo ); else *pSpellInfo = SpellInfo(); // reset to default values @@ -1439,7 +1439,6 @@ SpellInfo * ImpEditEngine::CreateSpellInfo( bool bMultipleDocs ) // further changes elsewhere to work properly) pSpellInfo->aSpellStart = EPaM(); pSpellInfo->aSpellTo = EPaM( EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND ); - return pSpellInfo; } @@ -1459,7 +1458,7 @@ EESpellState ImpEditEngine::Spell( EditView* pEditView, bool bMultipleDoc ) } EditSelection aCurSel( pEditView->pImpEditView->GetEditSelection() ); - pSpellInfo = CreateSpellInfo( bMultipleDoc ); + CreateSpellInfo( bMultipleDoc ); bool bIsStart = false; if ( bMultipleDoc ) @@ -1483,8 +1482,7 @@ EESpellState ImpEditEngine::Spell( EditView* pEditView, bool bMultipleDoc ) pEditView->ShowCursor( true, false ); } EESpellState eState = pSpellInfo->eState; - delete pSpellInfo; - pSpellInfo = nullptr; + pSpellInfo.reset(); return eState; } @@ -1928,7 +1926,7 @@ bool ImpEditEngine::SpellSentence(EditView const & rEditView, bool bRet = false; EditSelection aCurSel( rEditView.pImpEditView->GetEditSelection() ); if(!pSpellInfo) - pSpellInfo = CreateSpellInfo( true ); + CreateSpellInfo( true ); pSpellInfo->aCurSentenceStart = aCurSel.Min(); DBG_ASSERT( xSpeller.is(), "No spell checker set!" ); pSpellInfo->aLastSpellPortions.clear();