From a7ea04397bf8c6749c84fe8f0d9afc80e4cf6bb2 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 17 Jan 2019 16:47:17 +0200 Subject: use unique_ptr in sc Change-Id: I14ccb215e895b607c7244b420ee2cbaea8112b15 Reviewed-on: https://gerrit.libreoffice.org/66549 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sc/source/core/data/patattr.cxx | 7 +++---- sc/source/core/data/table4.cxx | 7 ++----- sc/source/core/data/validat.cxx | 9 ++++----- sc/source/core/tool/editutil.cxx | 6 +++--- sc/source/ui/app/inputhdl.cxx | 7 +++---- sc/source/ui/docshell/docsh5.cxx | 8 ++++---- 6 files changed, 19 insertions(+), 25 deletions(-) (limited to 'sc') diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx index 1508663e0feb..d9850d7b9ed9 100644 --- a/sc/source/core/data/patattr.cxx +++ b/sc/source/core/data/patattr.cxx @@ -1021,7 +1021,7 @@ ScPatternAttr* ScPatternAttr::PutInPool( ScDocument* pDestDoc, ScDocument* pSrcD SfxItemState eItemState = pSrcSet->GetItemState( nAttrId, false, &pSrcItem ); if (eItemState==SfxItemState::SET) { - SfxPoolItem* pNewItem = nullptr; + std::unique_ptr pNewItem; if ( nAttrId == ATTR_VALIDDATA ) { @@ -1036,7 +1036,7 @@ ScPatternAttr* ScPatternAttr::PutInPool( ScDocument* pDestDoc, ScDocument* pSrcD if ( pOldData ) nNewIndex = pDestDoc->AddValidationEntry( *pOldData ); } - pNewItem = new SfxUInt32Item( ATTR_VALIDDATA, nNewIndex ); + pNewItem.reset(new SfxUInt32Item( ATTR_VALIDDATA, nNewIndex )); } else if ( nAttrId == ATTR_VALUE_FORMAT && pDestDoc->GetFormatExchangeList() ) { @@ -1047,14 +1047,13 @@ ScPatternAttr* ScPatternAttr::PutInPool( ScDocument* pDestDoc, ScDocument* pSrcD if (it != pDestDoc->GetFormatExchangeList()->end()) { sal_uInt32 nNewFormat = it->second; - pNewItem = new SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ); + pNewItem.reset(new SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat )); } } if ( pNewItem ) { pDestSet->Put(*pNewItem); - delete pNewItem; } else pDestSet->Put(*pSrcItem); diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx index 12a23a452553..b01df1402c74 100644 --- a/sc/source/core/data/table4.cxx +++ b/sc/source/core/data/table4.cxx @@ -1954,10 +1954,10 @@ void ScTable::AutoFormat( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW ScAutoFormatData* pData = rFormat.findByIndex(nFormatNo); if (pData) { - ScPatternAttr* pPatternAttrs[16]; + std::unique_ptr pPatternAttrs[16]; for (sal_uInt8 i = 0; i < 16; ++i) { - pPatternAttrs[i] = new ScPatternAttr(pDocument->GetPool()); + pPatternAttrs[i].reset(new ScPatternAttr(pDocument->GetPool())); pData->FillToItemSet(i, pPatternAttrs[i]->GetItemSet(), *pDocument); } @@ -2077,9 +2077,6 @@ void ScTable::AutoFormat( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW } // for nCol } // if not equal Column } // if not all equal - - for (ScPatternAttr* pPatternAttr : pPatternAttrs) - delete pPatternAttr; } // if AutoFormatData != NULL } // if ValidColRow } diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx index c194da86e3e2..dc262625b794 100644 --- a/sc/source/core/data/validat.cxx +++ b/sc/source/core/data/validat.cxx @@ -774,7 +774,7 @@ bool ScValidationData::GetSelectionFromFormula( for( nCol = 0; nCol < nCols ; nCol++ ) { ScTokenArray aCondTokArr; - ScTypedStrData* pEntry = nullptr; + std::unique_ptr pEntry; OUString aValStr; ScMatrixValue nMatVal = pValues->Get( nCol, nRow); @@ -794,7 +794,7 @@ bool ScValidationData::GetSelectionFromFormula( } if( nullptr != pStrings ) - pEntry = new ScTypedStrData( aValStr, 0.0, ScTypedStrData::Standard); + pEntry.reset(new ScTypedStrData( aValStr, 0.0, ScTypedStrData::Standard)); if (!rCell.isEmpty() && rMatch < 0) aCondTokArr.AddString(rSPool.intern(aValStr)); @@ -831,7 +831,7 @@ bool ScValidationData::GetSelectionFromFormula( aCondTokArr.AddDouble( nMatVal.fVal ); } if( nullptr != pStrings ) - pEntry = new ScTypedStrData( aValStr, nMatVal.fVal, ScTypedStrData::Value); + pEntry.reset(new ScTypedStrData( aValStr, nMatVal.fVal, ScTypedStrData::Value)); } if (rMatch < 0 && !rCell.isEmpty() && IsEqualToTokenArray(rCell, rPos, aCondTokArr)) @@ -842,10 +842,9 @@ bool ScValidationData::GetSelectionFromFormula( return true; } - if( nullptr != pEntry ) + if( pEntry ) { pStrings->push_back(*pEntry); - delete pEntry; n++; } } diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx index 16df499e903f..5f3af3d55702 100644 --- a/sc/source/core/tool/editutil.cxx +++ b/sc/source/core/tool/editutil.cxx @@ -623,7 +623,7 @@ void ScEditEngineDefaulter::RepeatDefaults() void ScEditEngineDefaulter::RemoveParaAttribs() { - SfxItemSet* pCharItems = nullptr; + std::unique_ptr pCharItems; bool bUpdateMode = GetUpdateMode(); if ( bUpdateMode ) SetUpdateMode( false ); @@ -641,7 +641,7 @@ void ScEditEngineDefaulter::RemoveParaAttribs() if ( !pDefaults || *pParaItem != pDefaults->Get(nWhich) ) { if (!pCharItems) - pCharItems = new SfxItemSet( GetEmptyItemSet() ); + pCharItems.reset(new SfxItemSet( GetEmptyItemSet() )); pCharItems->Put( *pParaItem ); } } @@ -679,7 +679,7 @@ void ScEditEngineDefaulter::RemoveParaAttribs() nStart = nEnd; } - DELETEZ( pCharItems ); + pCharItems.reset(); } if ( rParaAttribs.Count() ) diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx index aabcc77ec6a4..622967c15fcf 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -2747,7 +2747,7 @@ void ScInputHandler::EnterHandler( ScEnterMode nBlockMode ) // Find common (cell) attributes before RemoveAdjust if ( pActiveViewSh && bUniformAttribs ) { - SfxItemSet* pCommonAttrs = nullptr; + std::unique_ptr pCommonAttrs; for (sal_uInt16 nId = EE_CHAR_START; nId <= EE_CHAR_END; nId++) { SfxItemState eState = aOldAttribs.GetItemState( nId, false, &pItem ); @@ -2757,7 +2757,7 @@ void ScInputHandler::EnterHandler( ScEnterMode nBlockMode ) *pItem != pEditDefaults->Get(nId) ) { if ( !pCommonAttrs ) - pCommonAttrs = new SfxItemSet( mpEditEngine->GetEmptyItemSet() ); + pCommonAttrs.reset(new SfxItemSet( mpEditEngine->GetEmptyItemSet() )); pCommonAttrs->Put( *pItem ); } } @@ -2766,8 +2766,7 @@ void ScInputHandler::EnterHandler( ScEnterMode nBlockMode ) { ScDocument* pDoc = pActiveViewSh->GetViewData().GetDocument(); pCellAttrs = o3tl::make_unique(pDoc->GetPool()); - pCellAttrs->GetFromEditItemSet( pCommonAttrs ); - delete pCommonAttrs; + pCellAttrs->GetFromEditItemSet( pCommonAttrs.get() ); } } diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx index 54dbfbd115a6..3fdd844cca2f 100644 --- a/sc/source/ui/docshell/docsh5.cxx +++ b/sc/source/ui/docshell/docsh5.cxx @@ -992,10 +992,10 @@ bool ScDocShell::MoveTable( SCTAB nSrcTab, SCTAB nDestTab, bool bCopy, bool bRec return true; // nothing to do, but valid } - ScProgress* pProgress = new ScProgress(this, ScResId(STR_UNDO_MOVE_TAB), - m_aDocument.GetCodeCount(), true); - bool bDone = m_aDocument.MoveTab( nSrcTab, nDestTab, pProgress ); - delete pProgress; + std::unique_ptr pProgress(new ScProgress(this, ScResId(STR_UNDO_MOVE_TAB), + m_aDocument.GetCodeCount(), true)); + bool bDone = m_aDocument.MoveTab( nSrcTab, nDestTab, pProgress.get() ); + pProgress.reset(); if (!bDone) { return false; -- cgit