sc/source/ui/view/tabvwsh4.cxx |   22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

New commits:
commit 1b5b22902e22a24f2782057ec2598b0370aeccad
Author:     Noel Grandin <[email protected]>
AuthorDate: Thu Jan 29 19:22:33 2026 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Thu Jan 29 20:52:47 2026 +0100

    tdf#166121 speed up de-duplication by merge deletes
    
    takes the de-dupe time from 4s to <1s,
    and the undo time from 14s to <1s.
    
    Change-Id: I31835775d2c005059fc133c1f88ecff84733251e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198376
    Reviewed-by: Noel Grandin <[email protected]>
    Tested-by: Jenkins

diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx
index bff3d4930f1f..d503fba5949a 100644
--- a/sc/source/ui/view/tabvwsh4.cxx
+++ b/sc/source/ui/view/tabvwsh4.cxx
@@ -2077,19 +2077,27 @@ void ScTabViewShell::HandleDuplicateRecordsRemove(const 
rtl::Reference<ScTableSh
     if (bDuplicateRows)
     {
         std::vector<uno::Sequence<uno::Any>> aUnionArray;
-        sal_uInt32 nRow = bIncludesHeaders ? 1 : 0;
-        sal_uInt32 lRows = aDataArray.getLength();
+        SCROW nRow = bIncludesHeaders ? 1 : 0;
+        SCROW lRows = aDataArray.getLength();
         sal_uInt32 nDeleteCount = 0;
+        SCROW nPrevRowDeleted = -1;
+        std::vector<table::CellRangeAddress> aDelRanges;
 
         while (nRow < lRows)
         {
             if (lcl_CheckInArrayRows(aUnionArray, aDataArray[nRow], 
rSelectedEntries))
             {
-                table::CellRangeAddress aCellRange(aRange.Sheet, 
aRange.StartColumn,
-                                            aRange.StartRow + nRow - 
nDeleteCount,
-                                            aRange.EndColumn, aRange.StartRow 
+ nRow - nDeleteCount);
-                ActiveSheet->removeRange(aCellRange, sheet::CellDeleteMode_UP);
+                if (nPrevRowDeleted + 1 == nRow)
+                    aDelRanges.back().EndRow++;
+                else
+                {
+                    table::CellRangeAddress aCellRange(aRange.Sheet, 
aRange.StartColumn,
+                                                aRange.StartRow + nRow - 
nDeleteCount,
+                                                aRange.EndColumn, 
aRange.StartRow + nRow - nDeleteCount);
+                    aDelRanges.push_back(aCellRange);
+                }
                 ++nDeleteCount;
+                nPrevRowDeleted = nRow;
             }
             else
             {
@@ -2097,6 +2105,8 @@ void ScTabViewShell::HandleDuplicateRecordsRemove(const 
rtl::Reference<ScTableSh
             }
             ++nRow;
         }
+        for (const table::CellRangeAddress & rRange : aDelRanges)
+            ActiveSheet->removeRange(rRange, sheet::CellDeleteMode_UP);
     }
     else
     {

Reply via email to