sc/source/core/data/table2.cxx |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

New commits:
commit 7adb3757944452a0f3a1a12fee1dd504eb90a1df
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Mon Feb 14 12:33:47 2022 +0100
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Mon Feb 14 16:29:19 2022 +0100

    don't gradually move columns to a large distance (tdf#144380)
    
    The old code was trying to move the changed columns, each one in
    a loop, which is O(N^2). Since the changed columns are those that
    are inserted/deleted (and thus the content shouldn't matter),
    instead move all the columns after them to the right place,
    which is O(N).
    
    Change-Id: Iad29b945fe9b3525ece43523ba04ecf306797c6e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129911
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 759a7858ec83..cde674b07360 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -305,9 +305,8 @@ void ScTable::InsertCol(
 
     if ((nStartRow == 0) && (nEndRow == rDocument.MaxRow()))
     {
-        for (SCSIZE i=0; i < nSize; i++)
-            for (SCCOL nCol = aCol.size() - 1; nCol > nStartCol; nCol--)
-                aCol[nCol].SwapCol(aCol[nCol-1]);
+        for (SCCOL nCol = aCol.size() - 1 - nSize; nCol >= nStartCol; --nCol)
+            aCol[nCol].SwapCol(aCol[nCol+nSize]);
     }
     else
     {
@@ -390,9 +389,8 @@ void ScTable::DeleteCol(
 
     if ((nStartRow == 0) && (nEndRow == rDocument.MaxRow()))
     {
-        for (SCSIZE i=0; i < nSize; i++)
-            for (SCCOL nCol = nStartCol; nCol < aCol.size() - 1; nCol++)
-                aCol[nCol].SwapCol(aCol[nCol+1]);
+        for (SCCOL nCol = nStartCol + nSize; nCol < aCol.size(); ++nCol)
+            aCol[nCol].SwapCol(aCol[nCol - nSize]);
     }
     else
     {

Reply via email to