sc/inc/column.hxx              |    6 ++++++
 sc/source/core/data/column.cxx |    6 +++---
 sc/source/core/data/table1.cxx |   25 ++++++++++---------------
 sc/source/core/data/table2.cxx |    6 +++++-
 4 files changed, 24 insertions(+), 19 deletions(-)

New commits:
commit 890493c3dc058ddedf9d6629abf178f7898c7342
Author:     Luboš Luňák <[email protected]>
AuthorDate: Wed May 18 18:48:23 2022 +0200
Commit:     Luboš Luňák <[email protected]>
CommitDate: Thu May 19 06:52:29 2022 +0200

    don't allocate unnecessary columns when inserting a row
    
    Change-Id: I616ef20dc1295ce17c4877ff367815bb6a90b7a1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134551
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Luboš Luňák <[email protected]>

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 7797e58c2f76..293798fd183f 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -171,6 +171,7 @@ public:
     void        ChangeSelectionIndent( bool bIncrement, const ScMarkData& 
rMark, SCCOL nCol );
 
     bool        TestInsertRow( SCSIZE nSize ) const;
+    void        InsertRow( SCROW nStartRow, SCSIZE nSize );
 };
 
 // Use protected inheritance to prevent publishing some internal ScColumnData
@@ -1038,4 +1039,9 @@ inline bool ScColumnData::TestInsertRow( SCSIZE nSize ) 
const
     return pAttrArray->TestInsertRow( nSize );
 }
 
+inline void ScColumnData::InsertRow( SCROW nStartRow, SCSIZE nSize )
+{
+    pAttrArray->InsertRow( nStartRow, nSize );
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index a6293094f9a5..51d039fdb5dd 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -2390,13 +2390,13 @@ bool ScColumn::UpdateReferenceOnCopy( 
sc::RefUpdateContext& rCxt, ScDocument* pU
 
 bool ScColumn::UpdateReference( sc::RefUpdateContext& rCxt, ScDocument* 
pUndoDoc )
 {
-    if (rCxt.meMode == URM_COPY)
-        return UpdateReferenceOnCopy(rCxt, pUndoDoc);
-
     if (IsEmptyData() || GetDoc().IsClipOrUndo())
         // Cells in this column are all empty, or clip or undo doc. No update 
needed.
         return false;
 
+    if (rCxt.meMode == URM_COPY)
+        return UpdateReferenceOnCopy(rCxt, pUndoDoc);
+
     std::vector<SCROW> aBounds;
 
     bool bThisColShifted = (rCxt.maRange.aStart.Tab() <= nTab && nTab <= 
rCxt.maRange.aEnd.Tab() &&
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index a3003677d431..e65aa194f9f7 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1819,19 +1819,6 @@ void ScTable::UpdateReference(
     sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc, bool bIncludeDraw, bool 
bUpdateNoteCaptionPos )
 {
     bool bUpdated = false;
-    SCCOL i;
-    SCCOL iMax;
-    if (rCxt.meMode == URM_COPY )
-    {
-        i = rCxt.maRange.aStart.Col();
-        iMax = rCxt.maRange.aEnd.Col();
-    }
-    else
-    {
-        i = 0;
-        iMax = rDocument.MaxCol();
-    }
-
     UpdateRefMode eUpdateRefMode = rCxt.meMode;
     SCCOL nDx = rCxt.mnColDelta;
     SCROW nDy = rCxt.mnRowDelta;
@@ -1844,8 +1831,16 @@ void ScTable::UpdateReference(
     if (mpRangeName)
         mpRangeName->UpdateReference(rCxt, nTab);
 
-    for ( ; i<=iMax; i++)
-        bUpdated |= CreateColumnIfNotExists(i).UpdateReference(rCxt, pUndoDoc);
+    if (rCxt.meMode == URM_COPY )
+    {
+        for( SCCOL col : GetAllocatedColumnsRange( rCxt.maRange.aStart.Col(), 
rCxt.maRange.aEnd.Col()))
+            bUpdated |= aCol[col].UpdateReference(rCxt, pUndoDoc);
+    }
+    else
+    {
+        for( SCCOL col : GetAllocatedColumnsRange( 0, rDocument.MaxCol()))
+            bUpdated |= aCol[col].UpdateReference(rCxt, pUndoDoc);
+    }
 
     if ( bIncludeDraw )
         UpdateDrawRef( eUpdateRefMode, nCol1, nRow1, nTab1, nCol2, nRow2, 
nTab2, nDx, nDy, nDz, bUpdateNoteCaptionPos );
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 230e26166a12..5943feb9e5f6 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -186,8 +186,9 @@ void ScTable::InsertRow( SCCOL nStartCol, SCCOL nEndCol, 
SCROW nStartRow, SCSIZE
         }
     }
 
-    for (SCCOL j=nStartCol; j<=nEndCol; j++)
+    for (SCCOL j : GetAllocatedColumnsRange(nStartCol, nEndCol))
         aCol[j].InsertRow( nStartRow, nSize );
+    aDefaultColData.InsertRow( nStartRow, nSize );
 
     mpCondFormatList->InsertRow(nTab, nStartCol, nEndCol, nStartRow, nSize);
 
commit 0ff5b5f69d9323fadeac31614ea216bb55fae9f5
Author:     Luboš Luňák <[email protected]>
AuthorDate: Wed May 18 18:45:18 2022 +0200
Commit:     Luboš Luňák <[email protected]>
CommitDate: Thu May 19 06:52:16 2022 +0200

    actually insert the column(s) in ScTable::InsertCol()
    
    This was broken if the all the columns weren't allocated, since
    at least in the full-column mode it was swapping the last empty
    columns in the place of the new ones, but without all columns
    allocated there possibly weren't last empty columns, so it was
    instead swapping in last data columns.
    
    Change-Id: I21552f0eb296b0df5507677510a8b85fccb1ae5a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134550
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Luboš Luňák <[email protected]>

diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index f42d35f7bb61..230e26166a12 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -308,8 +308,11 @@ void ScTable::InsertCol(
         }
     }
 
+    // Make sure there are enough columns at the end.
+    CreateColumnIfNotExists(std::min<SCCOL>(rDocument.MaxCol(), 
std::max(nStartCol, aCol.size()) + nSize - 1 ));
     if ((nStartRow == 0) && (nEndRow == rDocument.MaxRow()))
     {
+        // Move existing columns back, this will swap last empty columns in 
the inserted place.
         for (SCCOL nCol = aCol.size() - 1 - nSize; nCol >= nStartCol; --nCol)
             aCol[nCol].SwapCol(aCol[nCol+nSize]);
     }

Reply via email to