sc/inc/fillinfo.hxx                     |    2 +-
 sc/qa/unit/ucalc_condformat.cxx         |    2 +-
 sc/source/core/data/fillinfo.cxx        |    9 +++++++--
 sc/source/ui/app/inputhdl.cxx           |    2 +-
 sc/source/ui/miscdlgs/datatableview.cxx |    2 +-
 sc/source/ui/view/gridwin.cxx           |    2 +-
 sc/source/ui/view/gridwin4.cxx          |    4 ++--
 sc/source/ui/view/printfun.cxx          |    6 +++---
 8 files changed, 17 insertions(+), 12 deletions(-)

New commits:
commit 17fc445938dedb05125a6d6a5b4ce7f34ea95f59
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Thu Feb 1 12:47:53 2024 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Sat Feb 10 22:08:38 2024 +0100

    perf: limit to max 1024 rows in cases where we originally allocated 1024 
rows
    
    so everywhere before:
    
    commit a86c00414a43c5d87981ffae1018cb242c5e5e1d
    Date:   Fri Jan 19 14:27:10 2024 +0200
    
        cool#6893 reduce allocation in ScGridWindow::PaintTile
    
    where ScTableInfo was used with no args, pass true to indicate this is
    just a hint, and where it was originally passed an explicit number, pass
    false for "hint"
    
    When hint is true limit to max of 1024 rows, and the issue
    is visible in ScGridWindow::UpdateFormulaRange at
    
https://github.com/CollaboraOnline/online/issues/6893#issuecomment-1921141048
    
    CppunitTest_sc_uicalc contains some examples of these where hidden rows
    triggers the over allocs
    
    Change-Id: Iebe890c3ac967800b60150aaa71f7e845a021f60
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162875
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    (cherry picked from commit e4410bd37fc018c851b5ebf9cf011d59af6a2ad9)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163016
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163060
    Tested-by: Jenkins

diff --git a/sc/inc/fillinfo.hxx b/sc/inc/fillinfo.hxx
index 8ed8ac63b98f..caecd6a7072b 100644
--- a/sc/inc/fillinfo.hxx
+++ b/sc/inc/fillinfo.hxx
@@ -268,7 +268,7 @@ struct ScTableInfo
     SCSIZE              mnArrCapacity;
     bool                mbPageMode;
 
-    explicit            ScTableInfo(SCROW nStartRow, SCROW nEndRow);
+    explicit            ScTableInfo(SCROW nStartRow, SCROW nEndRow, bool 
bHintOnly);
                         ~ScTableInfo();
     ScTableInfo(const ScTableInfo&) = delete;
     const ScTableInfo& operator=(const ScTableInfo&) = delete;
diff --git a/sc/qa/unit/ucalc_condformat.cxx b/sc/qa/unit/ucalc_condformat.cxx
index 3416e4a39dc8..c4dd685c41a8 100644
--- a/sc/qa/unit/ucalc_condformat.cxx
+++ b/sc/qa/unit/ucalc_condformat.cxx
@@ -366,7 +366,7 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testColorScaleInMergedCell)
     m_pDoc->DoMerge(0, 0, 0, 1, 0);  // A1:A2
     CPPUNIT_ASSERT(m_pDoc->IsMerged(ScAddress(0, 0, 0)));
 
-    ScTableInfo aTabInfo(0, 2);
+    ScTableInfo aTabInfo(0, 2, false);
     m_pDoc->FillInfo(aTabInfo, 0, 0, 0, 1, 0, 1, 1, false, false);
     RowInfo* pRowInfo = aTabInfo.mpRowInfo.get();
 
diff --git a/sc/source/core/data/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx
index b33a30f5fea2..8ab35f34c079 100644
--- a/sc/source/core/data/fillinfo.cxx
+++ b/sc/source/core/data/fillinfo.cxx
@@ -1074,14 +1074,19 @@ void ScDocument::FillInfo(
 
 /// We seem to need to allocate three extra rows here, not sure why
 ///
-ScTableInfo::ScTableInfo(SCROW nStartRow, SCROW nEndRow)
+ScTableInfo::ScTableInfo(SCROW nStartRow, SCROW nEndRow, bool bHintOnly)
     : mnArrCount(0)
     , mnArrCapacity(nEndRow - nStartRow + 4)
     , mbPageMode(false)
 {
     assert(nStartRow >= 0);
     assert(nEndRow >= nStartRow);
-    mpRowInfo.reset(new RowInfo[nEndRow - nStartRow + 4] {});
+    if (bHintOnly && mnArrCapacity > 1024)
+    {
+        SAL_INFO("sc.core", "ScTableInfo excessive capacity: " << 
mnArrCapacity << " start: " << nStartRow << " end: " << nEndRow);
+        mnArrCapacity = 1024;
+    }
+    mpRowInfo.reset(new RowInfo[mnArrCapacity] {});
 }
 
 ScTableInfo::~ScTableInfo()
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index ce397be3f6cd..745e69158d3b 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -523,7 +523,7 @@ ReferenceMark ScInputHandler::GetReferenceMark( const 
ScViewData& rViewData, ScD
     Fraction aZoomX = rViewData.GetZoomX();
     Fraction aZoomY = rViewData.GetZoomY();
 
-    ScTableInfo aTabInfo(nY1, nY2);
+    ScTableInfo aTabInfo(nY1, nY2, true);
     pDocSh->GetDocument().FillInfo( aTabInfo, nX1, nY1, nX2, nY2,
                                     nTab, nPPTX, nPPTY, false, false );
 
diff --git a/sc/source/ui/miscdlgs/datatableview.cxx 
b/sc/source/ui/miscdlgs/datatableview.cxx
index 2ad901f4b110..e6f7373e0491 100644
--- a/sc/source/ui/miscdlgs/datatableview.cxx
+++ b/sc/source/ui/miscdlgs/datatableview.cxx
@@ -257,7 +257,7 @@ void ScDataTableView::Paint(vcl::RenderContext& 
rRenderContext, const tools::Rec
     SCCOL nMaxVisibleCol = findColFromPos(aSize.Width() - mnScrollBarSize, 
mpDoc.get(), mnFirstVisibleCol);
     SCROW nMaxVisibleRow = findRowFromPos(aSize.Height(), mpDoc.get(), 
mnFirstVisibleRow);
 
-    ScTableInfo aTableInfo(mnFirstVisibleRow, nMaxVisibleRow);
+    ScTableInfo aTableInfo(mnFirstVisibleRow, nMaxVisibleRow, true);
     mpDoc->FillInfo(aTableInfo, mnFirstVisibleCol, mnFirstVisibleRow, 
nMaxVisibleCol, nMaxVisibleRow, 0, 0.06666, 0.06666, false, false);
     ScOutputData aOutput(&rRenderContext, OUTTYPE_WINDOW, aTableInfo, 
mpDoc.get(), 0,
             nRowHeaderWidth, nColHeaderHeight, mnFirstVisibleCol, 
mnFirstVisibleRow, nMaxVisibleCol, nMaxVisibleRow, nPPTX, nPPTY);
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 44a5393c0a8a..71364aaf172a 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -5170,7 +5170,7 @@ void ScGridWindow::UpdateFormulaRange(SCCOL nX1, SCROW 
nY1, SCCOL nX2, SCROW nY2
     double nPPTX = mrViewData.GetPPTX();
     double nPPTY = mrViewData.GetPPTY();
 
-    ScTableInfo aTabInfo(nY1, nY2);
+    ScTableInfo aTabInfo(nY1, nY2, true);
     rDoc.FillInfo( aTabInfo, nX1, nY1, nX2, nY2, nTab, nPPTX, nPPTY, false, 
false );
 
     Fraction aZoomX = mrViewData.GetZoomX();
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 224aca8584bb..785cf19d5e04 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -529,7 +529,7 @@ void ScGridWindow::Draw( SCCOL nX1, SCROW nY1, SCCOL nX2, 
SCROW nY2, ScUpdateMod
 
     // data block
 
-    ScTableInfo aTabInfo(nY1, nY2);
+    ScTableInfo aTabInfo(nY1, nY2, true);
     rDoc.FillInfo( aTabInfo, nX1, nY1, nX2, nY2, nTab,
                    nPPTX, nPPTY, false, rOpts.GetOption(VOPT_FORMULAS),
                    &mrViewData.GetMarkData() );
@@ -1575,7 +1575,7 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice,
     aAbsMode.SetOrigin(aOrigin);
     rDevice.SetMapMode(aAbsMode);
 
-    ScTableInfo aTabInfo(nTopLeftTileRow, nBottomRightTileRow);
+    ScTableInfo aTabInfo(nTopLeftTileRow, nBottomRightTileRow, false);
     rDoc.FillInfo(aTabInfo, nTopLeftTileCol, nTopLeftTileRow,
                    nBottomRightTileCol, nBottomRightTileRow,
                    nTab, fPPTX, fPPTY, false, false);
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index a4e934280a28..d9ba4a0064a9 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -571,7 +571,7 @@ void ScPrintFunc::DrawToDev(ScDocument& rDoc, OutputDevice* 
pDev, double /* nPri
 
     //  Assemble data
 
-    ScTableInfo aTabInfo(nY1, nY2);
+    ScTableInfo aTabInfo(nY1, nY2, true);
     rDoc.FillInfo( aTabInfo, nX1, nY1, nX2, nY2, nTab,
                    nScaleX, nScaleY, false, bFormula );
     lcl_HidePrint( aTabInfo, nX1, nX2 );
@@ -1434,7 +1434,7 @@ void ScPrintFunc::DrawBorder( tools::Long nScrX, 
tools::Long nScrY, tools::Long
     pBorderDoc->InitUndo( rDoc, 0,0, true,true );
     pBorderDoc->ApplyAttr( 0,0,0, *pBorderData );
 
-    ScTableInfo aTabInfo(0, 1);
+    ScTableInfo aTabInfo(0, 1, false);
     pBorderDoc->FillInfo( aTabInfo, 0,0, 0,0, 0,
                                         nScaleX, nScaleY, false, false );
     OSL_ENSURE(aTabInfo.mnArrCount,"nArrCount == 0");
@@ -1646,7 +1646,7 @@ void ScPrintFunc::PrintArea( SCCOL nX1, SCROW nY1, SCCOL 
nX2, SCROW nY2,
 
                     //  Assemble data
 
-    ScTableInfo aTabInfo(nY1, nY2);
+    ScTableInfo aTabInfo(nY1, nY2, true);
     rDoc.FillInfo( aTabInfo, nX1, nY1, nX2, nY2, nPrintTab,
                                         nScaleX, nScaleY, true, 
aTableParam.bFormulas );
     lcl_HidePrint( aTabInfo, nX1, nX2 );

Reply via email to