[Libreoffice-commits] core.git: sc/inc sc/source

Takeshi Abe tabe at fixedpoint.jp
Wed Jul 11 07:37:16 UTC 2018


 sc/inc/chgtrack.hxx              |    6 +++---
 sc/source/core/tool/chgtrack.cxx |   34 +++++++++++++---------------------
 2 files changed, 16 insertions(+), 24 deletions(-)

New commits:
commit bd71dccb2644257000cf6481c50af1f10f4d63c5
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Mon Jul 9 21:31:42 2018 +0900

    sc: Prefer std::vector to std::deque or std::stack
    
    as the queue is modified only by either appending or clear().
    
    Change-Id: I6866c047eaf7149221c77ff4f1f3759dbf10492e
    Reviewed-on: https://gerrit.libreoffice.org/57182
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/inc/chgtrack.hxx b/sc/inc/chgtrack.hxx
index a23744c53a08..ef7a237645c2 100644
--- a/sc/inc/chgtrack.hxx
+++ b/sc/inc/chgtrack.hxx
@@ -20,11 +20,11 @@
 #ifndef INCLUDED_SC_INC_CHGTRACK_HXX
 #define INCLUDED_SC_INC_CHGTRACK_HXX
 
-#include <deque>
 #include <map>
 #include <memory>
 #include <set>
 #include <stack>
+#include <vector>
 
 #include <tools/color.hxx>
 #include <tools/datetime.hxx>
@@ -827,8 +827,8 @@ struct ScChangeTrackMsgInfo
 };
 
 // MsgQueue for notification via ModifiedLink
-typedef std::deque<ScChangeTrackMsgInfo*> ScChangeTrackMsgQueue;
-typedef std::stack<ScChangeTrackMsgInfo*> ScChangeTrackMsgStack;
+typedef std::vector<ScChangeTrackMsgInfo*> ScChangeTrackMsgQueue;
+typedef std::vector<ScChangeTrackMsgInfo*> ScChangeTrackMsgStack;
 typedef std::map<sal_uLong, ScChangeAction*> ScChangeActionMap;
 
 enum ScChangeTrackMergeState
diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx
index 29fffe7561e8..35c1d72dbe64 100644
--- a/sc/source/core/tool/chgtrack.cxx
+++ b/sc/source/core/tool/chgtrack.cxx
@@ -45,6 +45,7 @@
 #include <unotools/useroptions.hxx>
 #include <unotools/datetime.hxx>
 #include <sfx2/sfxsids.hrc>
+#include <algorithm>
 #include <memory>
 #include <boost/property_tree/json_parser.hpp>
 
@@ -2163,16 +2164,10 @@ void ScChangeTrack::ClearMsgQueue()
         delete pBlockModifyMsg;
         pBlockModifyMsg = nullptr;
     }
-    while ( !aMsgStackTmp.empty() )
-    {
-        delete aMsgStackTmp.top();
-        aMsgStackTmp.pop();
-    }
-    while ( !aMsgStackFinal.empty() )
-    {
-        delete aMsgStackFinal.top();
-        aMsgStackFinal.pop();
-    }
+    std::for_each(aMsgStackTmp.rbegin(), aMsgStackTmp.rend(), std::default_delete<ScChangeTrackMsgInfo>());
+    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)
@@ -2279,7 +2274,7 @@ void ScChangeTrack::StartBlockModify( ScChangeTrackMsgType eMsgType,
     if ( aModifiedLink.IsSet() )
     {
         if ( pBlockModifyMsg )
-            aMsgStackTmp.push( pBlockModifyMsg ); // Block in Block
+            aMsgStackTmp.push_back( pBlockModifyMsg ); // Block in Block
         pBlockModifyMsg = new ScChangeTrackMsgInfo;
         pBlockModifyMsg->eMsgType = eMsgType;
         pBlockModifyMsg->nStartAction = nStartAction;
@@ -2296,7 +2291,7 @@ void ScChangeTrack::EndBlockModify( sal_uLong nEndAction )
             {
                 pBlockModifyMsg->nEndAction = nEndAction;
                 // Blocks dissolved in Blocks
-                aMsgStackFinal.push( pBlockModifyMsg );
+                aMsgStackFinal.push_back( pBlockModifyMsg );
             }
             else
                 delete pBlockModifyMsg;
@@ -2304,19 +2299,16 @@ void ScChangeTrack::EndBlockModify( sal_uLong nEndAction )
                 pBlockModifyMsg = nullptr;
             else
             {
-                pBlockModifyMsg = aMsgStackTmp.top(); // Maybe Block in Block
-                aMsgStackTmp.pop();
+                pBlockModifyMsg = aMsgStackTmp.back(); // Maybe Block in Block
+                aMsgStackTmp.pop_back();
             }
         }
         if ( !pBlockModifyMsg )
         {
-            bool bNew = false;
-            while ( !aMsgStackFinal.empty() )
-            {
-                aMsgQueue.push_back( aMsgStackFinal.top() );
-                aMsgStackFinal.pop();
-                bNew = true;
-            }
+            bool bNew = !aMsgStackFinal.empty();
+            aMsgQueue.reserve(aMsgQueue.size() + aMsgStackFinal.size());
+            aMsgQueue.insert(aMsgQueue.end(), aMsgStackFinal.rbegin(), aMsgStackFinal.rend());
+            aMsgStackFinal.clear();
             if ( bNew )
                 aModifiedLink.Call( *this );
         }


More information about the Libreoffice-commits mailing list