sc/source/core/tool/grouparealistener.cxx |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

New commits:
commit fdcea8ccc8236b0975ac9c85dcabf9c663e4b627
Author:     Luboš Luňák <l.lu...@centrum.cz>
AuthorDate: Sun Feb 20 02:33:36 2022 +0100
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Sun Feb 20 08:01:40 2022 +0100

    make CollectCellAction sort cells by cell address (tdf#119083)
    
    Many calc algorithms perform better if they process cells ordered
    by tab,col,row. In the case of tdf#119083 it's
    ScDocument::TrackFormulas().
    
    Change-Id: I1eedefc0130f5cf95feb84a4160b7599d3a09fd6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130205
    Tested-by: Luboš Luňák <l.lu...@collabora.com>
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/sc/source/core/tool/grouparealistener.cxx 
b/sc/source/core/tool/grouparealistener.cxx
index 4c92475d9a3f..39b92625b5b8 100644
--- a/sc/source/core/tool/grouparealistener.cxx
+++ b/sc/source/core/tool/grouparealistener.cxx
@@ -63,8 +63,14 @@ public:
 
     void swapCells( std::vector<ScFormulaCell*>& rCells )
     {
-        // Remove duplicate before the swap.
-        std::sort(maCells.begin(), maCells.end());
+        // Remove duplicate before the swap. Take care to sort them by 
tab,col,row before sorting by pointer,
+        // as many calc algorithms perform better if cells are processed in 
this order.
+        std::sort(maCells.begin(), maCells.end(), [](const ScFormulaCell* 
cell1, const ScFormulaCell* cell2)
+            {
+                if( cell1->aPos != cell2->aPos )
+                    return cell1->aPos < cell2->aPos;
+                return cell1 < cell2;
+            });
         std::vector<ScFormulaCell*>::iterator it = 
std::unique(maCells.begin(), maCells.end());
         maCells.erase(it, maCells.end());
 

Reply via email to