diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-01-14 15:34:38 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-01-16 17:24:58 +0100 |
commit | 5d2f157b25305caaff914a756727b85451abb852 (patch) | |
tree | 2eff210e27f4032217cde2119245112872b56b3a /sc | |
parent | 9796738e1149a99f8b3ff687b0f72264ba3a56ff (diff) |
simplify ScChangeTrack queues
no need to store such small struct on the heap
Change-Id: I8d9c12082a40e1d24cf7d25cca7369e1bb034c7a
Reviewed-on: https://gerrit.libreoffice.org/66323
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/chgtrack.hxx | 7 | ||||
-rw-r--r-- | sc/source/core/tool/chgtrack.cxx | 44 | ||||
-rw-r--r-- | sc/source/ui/miscdlgs/acredlin.cxx | 13 |
3 files changed, 26 insertions, 38 deletions
diff --git a/sc/inc/chgtrack.hxx b/sc/inc/chgtrack.hxx index 5c5ba6b58bec..730494ab354d 100644 --- a/sc/inc/chgtrack.hxx +++ b/sc/inc/chgtrack.hxx @@ -32,6 +32,7 @@ #include <tools/link.hxx> #include <tools/solar.h> #include <unotools/options.hxx> +#include <boost/optional.hpp> #include "global.hxx" #include "bigrange.hxx" #include "scdllapi.h" @@ -799,8 +800,8 @@ struct ScChangeTrackMsgInfo }; // MsgQueue for notification via ModifiedLink -typedef std::vector<ScChangeTrackMsgInfo*> ScChangeTrackMsgQueue; -typedef std::vector<ScChangeTrackMsgInfo*> ScChangeTrackMsgStack; +typedef std::vector<ScChangeTrackMsgInfo> ScChangeTrackMsgQueue; +typedef std::vector<ScChangeTrackMsgInfo> ScChangeTrackMsgStack; typedef std::map<sal_uLong, ScChangeAction*> ScChangeActionMap; enum ScChangeTrackMergeState @@ -848,7 +849,7 @@ class ScChangeTrack : public utl::ConfigurationListener ScChangeActionLinkEntry* pLinkInsertRow; ScChangeActionLinkEntry* pLinkInsertTab; ScChangeActionLinkEntry* pLinkMove; - ScChangeTrackMsgInfo* pBlockModifyMsg; + boost::optional<ScChangeTrackMsgInfo> xBlockModifyMsg; ScDocument* pDoc; sal_uLong nActionMax; sal_uLong nGeneratedMin; diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx index b5402a540a3e..a296fcd9a772 100644 --- a/sc/source/core/tool/chgtrack.cxx +++ b/sc/source/core/tool/chgtrack.cxx @@ -2099,7 +2099,7 @@ void ScChangeTrack::Init() pLinkInsertRow = nullptr; pLinkInsertTab = nullptr; pLinkMove = nullptr; - pBlockModifyMsg = nullptr; + xBlockModifyMsg.reset(); nActionMax = 0; nGeneratedMin = SC_CHGTRACK_GENERATED_START; nMarkLastSaved = 0; @@ -2148,20 +2148,9 @@ void ScChangeTrack::DtorClear() void ScChangeTrack::ClearMsgQueue() { - if ( pBlockModifyMsg ) - { - delete pBlockModifyMsg; - pBlockModifyMsg = nullptr; - } - std::for_each(aMsgStackTmp.rbegin(), aMsgStackTmp.rend(), std::default_delete<ScChangeTrackMsgInfo>()); + xBlockModifyMsg.reset(); aMsgStackTmp.clear(); - std::for_each(aMsgStackFinal.rbegin(), aMsgStackFinal.rend(), std::default_delete<ScChangeTrackMsgInfo>()); aMsgStackFinal.clear(); - - ScChangeTrackMsgQueue::iterator itQueue; - for ( itQueue = aMsgQueue.begin(); itQueue != aMsgQueue.end(); ++itQueue) - delete *itQueue; - aMsgQueue.clear(); } @@ -2262,11 +2251,12 @@ void ScChangeTrack::StartBlockModify( ScChangeTrackMsgType eMsgType, { if ( aModifiedLink.IsSet() ) { - if ( pBlockModifyMsg ) - aMsgStackTmp.push_back( pBlockModifyMsg ); // Block in Block - pBlockModifyMsg = new ScChangeTrackMsgInfo; - pBlockModifyMsg->eMsgType = eMsgType; - pBlockModifyMsg->nStartAction = nStartAction; + if ( xBlockModifyMsg ) + aMsgStackTmp.push_back( *xBlockModifyMsg ); // Block in Block + xBlockModifyMsg = ScChangeTrackMsgInfo(); + xBlockModifyMsg->eMsgType = eMsgType; + xBlockModifyMsg->nStartAction = nStartAction; + xBlockModifyMsg->nEndAction = 0; } } @@ -2274,25 +2264,25 @@ void ScChangeTrack::EndBlockModify( sal_uLong nEndAction ) { if ( aModifiedLink.IsSet() ) { - if ( pBlockModifyMsg ) + if ( xBlockModifyMsg ) { - if ( pBlockModifyMsg->nStartAction <= nEndAction ) + if ( xBlockModifyMsg->nStartAction <= nEndAction ) { - pBlockModifyMsg->nEndAction = nEndAction; + xBlockModifyMsg->nEndAction = nEndAction; // Blocks dissolved in Blocks - aMsgStackFinal.push_back( pBlockModifyMsg ); + aMsgStackFinal.push_back( *xBlockModifyMsg ); } else - delete pBlockModifyMsg; + xBlockModifyMsg.reset(); if (aMsgStackTmp.empty()) - pBlockModifyMsg = nullptr; + xBlockModifyMsg.reset(); else { - pBlockModifyMsg = aMsgStackTmp.back(); // Maybe Block in Block + xBlockModifyMsg = aMsgStackTmp.back(); // Maybe Block in Block aMsgStackTmp.pop_back(); } } - if ( !pBlockModifyMsg ) + if ( !xBlockModifyMsg ) { bool bNew = !aMsgStackFinal.empty(); aMsgQueue.reserve(aMsgQueue.size() + aMsgStackFinal.size()); @@ -2314,7 +2304,7 @@ void ScChangeTrack::NotifyModified( ScChangeTrackMsgType eMsgType, { if ( aModifiedLink.IsSet() ) { - if ( !pBlockModifyMsg || pBlockModifyMsg->eMsgType != eMsgType || + if ( !xBlockModifyMsg || xBlockModifyMsg->eMsgType != eMsgType || (IsGenerated( nStartAction ) && (eMsgType == SC_CTM_APPEND || eMsgType == SC_CTM_REMOVE)) ) { // Append within Append e.g. not diff --git a/sc/source/ui/miscdlgs/acredlin.cxx b/sc/source/ui/miscdlgs/acredlin.cxx index ad4d2ba5e61c..25e95a525d34 100644 --- a/sc/source/ui/miscdlgs/acredlin.cxx +++ b/sc/source/ui/miscdlgs/acredlin.cxx @@ -1541,16 +1541,16 @@ IMPL_LINK( ScAcceptChgDlg, ChgTrackModHdl, ScChangeTrack&, rChgTrack, void) sal_uLong nStartAction; sal_uLong nEndAction; - for (const auto& pMsg : aMsgQueue) + for (const auto& rMsg : aMsgQueue) { - nStartAction = pMsg->nStartAction; - nEndAction = pMsg->nEndAction; + nStartAction = rMsg.nStartAction; + nEndAction = rMsg.nEndAction; if(!bIgnoreMsg) { bNoSelection=true; - switch(pMsg->eMsgType) + switch(rMsg.eMsgType) { case SC_CTM_APPEND: AppendChanges(&rChgTrack,nStartAction,nEndAction); break; @@ -1560,13 +1560,10 @@ IMPL_LINK( ScAcceptChgDlg, ChgTrackModHdl, ScChangeTrack&, rChgTrack, void) case SC_CTM_CHANGE: //bNeedsUpdate=true; UpdateEntrys(&rChgTrack,nStartAction,nEndAction); break; - default: - { + default: ; // added to avoid warnings - } } } - delete pMsg; } aMsgQueue.clear(); |