diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-20 16:18:50 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-23 08:15:43 +0200 |
commit | d23b20661c83ebb722e4602d0ef9d65ce1ecfa6d (patch) | |
tree | 47ac5280a9aa2824b17f6e8810f10989ef122d93 /ucb | |
parent | 16632fa9f5dfbe8bd6f34f719ac923e972f250ca (diff) |
loplugin:useuiqueptr in SortedEntryList and EventList
Change-Id: I15e6e29347dfce68e5631337bf2d3754bffdf864
Reviewed-on: https://gerrit.libreoffice.org/53234
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'ucb')
-rw-r--r-- | ucb/source/sorter/sortdynres.cxx | 13 | ||||
-rw-r--r-- | ucb/source/sorter/sortresult.cxx | 70 | ||||
-rw-r--r-- | ucb/source/sorter/sortresult.hxx | 20 |
3 files changed, 49 insertions, 54 deletions
diff --git a/ucb/source/sorter/sortdynres.cxx b/ucb/source/sorter/sortdynres.cxx index e3b20bd62539..32bc6f7a3761 100644 --- a/ucb/source/sorter/sortdynres.cxx +++ b/ucb/source/sorter/sortdynres.cxx @@ -307,13 +307,13 @@ void SortedDynamicResultSet::impl_notify( const ListEvent& Changes ) aWelcome.Old = mxTwo.get(); aWelcome.New = mxOne.get(); - ListAction *pWelcomeAction = new ListAction; + std::unique_ptr<ListAction> pWelcomeAction(new ListAction); pWelcomeAction->ActionInfo <<= aWelcome; pWelcomeAction->Position = 0; pWelcomeAction->Count = 0; pWelcomeAction->ListActionType = ListActionType::WELCOME; - maActions.Insert( pWelcomeAction ); + maActions.Insert( std::move(pWelcomeAction) ); } else { @@ -483,22 +483,17 @@ SortedDynamicResultSetFactory::createSortedDynamicResultSet( void EventList::Clear() { - for (ListAction* p : maData) - { - delete p; - } - maData.clear(); } void EventList::AddEvent( sal_IntPtr nType, sal_IntPtr nPos ) { - ListAction *pAction = new ListAction; + std::unique_ptr<ListAction> pAction(new ListAction); pAction->Position = nPos; pAction->Count = 1; pAction->ListActionType = nType; - Insert( pAction ); + Insert( std::move(pAction) ); } // SortedDynamicResultSetListener diff --git a/ucb/source/sorter/sortresult.cxx b/ucb/source/sorter/sortresult.cxx index e18360794bf4..f8b4b05b4bd5 100644 --- a/ucb/source/sorter/sortresult.cxx +++ b/ucb/source/sorter/sortresult.cxx @@ -1248,7 +1248,7 @@ void SortedResultSet::CopyData( SortedResultSet *pSource ) for ( i=1; i<nCount; i++ ) { - maS2O.Insert( new SortListData( rSrcS2O[ i ] ), i ); + maS2O.Insert( std::unique_ptr<SortListData>(new SortListData( rSrcS2O[ i ] )), i ); m_O2S.push_back(pSource->m_O2S[i]); } @@ -1269,8 +1269,7 @@ void SortedResultSet::Initialize( { BuildSortInfo( mxOriginal, xSortInfo, xCompFactory ); // Insert dummy at pos 0 - SortListData *pData = new SortListData( 0 ); - maS2O.Insert( pData, 0 ); + maS2O.Insert( std::unique_ptr<SortListData>(new SortListData( 0 )), 0 ); sal_IntPtr nIndex = 1; @@ -1280,10 +1279,10 @@ void SortedResultSet::Initialize( try { while ( mxOriginal->absolute( nIndex ) ) { - pData = new SortListData( nIndex ); - sal_IntPtr nPos = FindPos( pData, 1, nIndex-1 ); + std::unique_ptr<SortListData> pData(new SortListData( nIndex )); + sal_IntPtr nPos = FindPos( pData.get(), 1, nIndex-1 ); - maS2O.Insert( pData, nPos ); + maS2O.Insert( std::move(pData), nPos ); nIndex++; } @@ -1354,13 +1353,12 @@ void SortedResultSet::CheckProperties( sal_IntPtr nOldCount, bool bWasFinal ) void SortedResultSet::InsertNew( sal_IntPtr nPos, sal_IntPtr nCount ) { // for all entries in the msS20-list, which are >= nPos, increase by nCount - SortListData *pData; sal_IntPtr i, nEnd; nEnd = maS2O.Count(); for ( i=1; i<=nEnd; i++ ) { - pData = maS2O.GetData( i ); + SortListData *pData = maS2O.GetData( i ); if ( pData->mnCurPos >= nPos ) { pData->mnCurPos += nCount; @@ -1372,9 +1370,9 @@ void SortedResultSet::InsertNew( sal_IntPtr nPos, sal_IntPtr nCount ) for ( i=0; i<nCount; i++ ) { nEnd += 1; - pData = new SortListData( nEnd ); + std::unique_ptr<SortListData> pData(new SortListData( nEnd )); - maS2O.Insert( pData, nEnd ); // Insert( Value, Position ) + maS2O.Insert( std::move(pData), nEnd ); // Insert( Value, Position ) m_O2S.insert(m_O2S.begin() + nPos + i, nEnd); } @@ -1414,10 +1412,9 @@ void SortedResultSet::Remove( sal_IntPtr nPos, sal_IntPtr nCount, EventList *pEv } } - SortListData *pData = maS2O.Remove( nSortPos ); + std::unique_ptr<SortListData> pData = maS2O.Remove( nSortPos ); if ( pData->mbModified ) - m_ModList.erase(std::find(m_ModList.begin(), m_ModList.end(), pData)); - delete pData; + m_ModList.erase(std::find(m_ModList.begin(), m_ModList.end(), pData.get())); // generate remove Event, but not for new entries if ( nSortPos <= nOldLastSort ) @@ -1586,7 +1583,6 @@ void SortedResultSet::ResortModified( EventList* pList ) { sal_IntPtr nCompare, nCurPos, nNewPos; sal_IntPtr nStart, nEnd, nOffset, nVal; - ListAction *pAction; try { for (size_t i = 0; i < m_ModList.size(); ++i) @@ -1616,8 +1612,7 @@ void SortedResultSet::ResortModified( EventList* pList ) if ( nNewPos != nCurPos ) { // correct the lists! - maS2O.Remove( static_cast<sal_uInt32>(nCurPos) ); - maS2O.Insert( pData, nNewPos ); + maS2O.Move( static_cast<sal_uInt32>(nCurPos), nNewPos ); for (size_t j = 1; j < m_O2S.size(); ++j) { nVal = m_O2S[j]; @@ -1630,12 +1625,12 @@ void SortedResultSet::ResortModified( EventList* pList ) m_O2S[pData->mnCurPos] = nNewPos; - pAction = new ListAction; + std::unique_ptr<ListAction> pAction(new ListAction); pAction->Position = nCurPos; pAction->Count = 1; pAction->ListActionType = ListActionType::MOVED; pAction->ActionInfo <<= nNewPos-nCurPos; - pList->Insert( pAction ); + pList->Insert( std::move(pAction) ); } pList->AddEvent( ListActionType::PROPERTIES_CHANGED, nNewPos ); } @@ -1661,8 +1656,7 @@ void SortedResultSet::ResortNew( EventList* pList ) nNewPos = FindPos( pData, 1, mnLastSort ); if ( nNewPos != i ) { - maS2O.Remove( static_cast<sal_uInt32>(i) ); - maS2O.Insert( pData, nNewPos ); + maS2O.Move( static_cast<sal_uInt32>(i), nNewPos ); for (size_t j=1; j< m_O2S.size(); ++j) { nVal = m_O2S[j]; @@ -1692,38 +1686,44 @@ SortListData::SortListData( sal_IntPtr nPos ) mnOldPos = nPos; }; +SortedEntryList::SortedEntryList() +{ +} -void SortedEntryList::Clear() +SortedEntryList::~SortedEntryList() { - for (SortListData* p : maData) - { - delete p; - } +} +void SortedEntryList::Clear() +{ maData.clear(); } -void SortedEntryList::Insert( SortListData *pEntry, sal_IntPtr nPos ) +void SortedEntryList::Insert( std::unique_ptr<SortListData> pEntry, sal_IntPtr nPos ) { if ( nPos < static_cast<sal_IntPtr>(maData.size()) ) - maData.insert( maData.begin() + nPos, pEntry ); + maData.insert( maData.begin() + nPos, std::move(pEntry) ); else - maData.push_back( pEntry ); + maData.push_back( std::move(pEntry) ); } +void SortedEntryList::Move( sal_IntPtr nOldPos, sal_IntPtr nNewPos ) +{ + auto p = std::move(maData[nOldPos]); + maData.erase( maData.begin() + nOldPos ); + maData.insert(maData.begin() + nNewPos, std::move(p)); +} -SortListData* SortedEntryList::Remove( sal_IntPtr nPos ) +std::unique_ptr<SortListData> SortedEntryList::Remove( sal_IntPtr nPos ) { - SortListData *pData; + std::unique_ptr<SortListData> pData; if ( nPos < static_cast<sal_IntPtr>(maData.size()) ) { - pData = maData[ nPos ]; + pData = std::move(maData[ nPos ]); maData.erase( maData.begin() + nPos ); } - else - pData = nullptr; return pData; } @@ -1734,7 +1734,7 @@ SortListData* SortedEntryList::GetData( sal_IntPtr nPos ) SortListData *pData; if ( nPos < static_cast<sal_IntPtr>(maData.size()) ) - pData = maData[ nPos ]; + pData = maData[ nPos ].get(); else pData = nullptr; @@ -1747,7 +1747,7 @@ sal_IntPtr SortedEntryList::operator [] ( sal_IntPtr nPos ) const SortListData *pData; if ( nPos < static_cast<sal_IntPtr>(maData.size()) ) - pData = maData[ nPos ]; + pData = maData[ nPos ].get(); else pData = nullptr; diff --git a/ucb/source/sorter/sortresult.hxx b/ucb/source/sorter/sortresult.hxx index f97f9050c6bc..fef58fb2341e 100644 --- a/ucb/source/sorter/sortresult.hxx +++ b/ucb/source/sorter/sortresult.hxx @@ -52,37 +52,37 @@ class PropertyChangeListeners_Impl; class SortedEntryList { - std::deque < SortListData* > maData; + std::deque < std::unique_ptr<SortListData> > maData; public: - SortedEntryList(){} - ~SortedEntryList(){ Clear(); } + SortedEntryList(); + ~SortedEntryList(); sal_uInt32 Count() const { return static_cast<sal_uInt32>(maData.size()); } void Clear(); - void Insert( SortListData *pEntry, sal_IntPtr nPos ); - SortListData* Remove( sal_IntPtr nPos ); + void Insert( std::unique_ptr<SortListData> pEntry, sal_IntPtr nPos ); + std::unique_ptr<SortListData> Remove( sal_IntPtr nPos ); SortListData* GetData( sal_IntPtr nPos ); + void Move( sal_IntPtr nOldPos, sal_IntPtr nNewPos ); - sal_IntPtr operator [] ( sal_IntPtr nPos ) const; + sal_IntPtr operator [] ( sal_IntPtr nPos ) const; }; class EventList { - std::deque < css::ucb::ListAction* > maData; + std::deque < std::unique_ptr<css::ucb::ListAction> > maData; public: EventList(){} - ~EventList(){ Clear(); } sal_uInt32 Count() { return static_cast<sal_uInt32>(maData.size()); } void AddEvent( sal_IntPtr nType, sal_IntPtr nPos ); - void Insert( css::ucb::ListAction *pAction ) { maData.push_back( pAction ); } + void Insert( std::unique_ptr<css::ucb::ListAction> pAction ) { maData.push_back( std::move(pAction) ); } void Clear(); - css::ucb::ListAction* GetAction( sal_IntPtr nIndex ) { return maData[ nIndex ]; } + css::ucb::ListAction* GetAction( sal_IntPtr nIndex ) { return maData[ nIndex ].get(); } }; |