core.git: Branch 'distro/collabora/co-24.04' - sc/inc sc/qa sc/source

2024-05-22 Thread Balazs Varga (via logerrit)
 sc/inc/queryiter.hxx|   32 
 sc/inc/rangecache.hxx   |   19 
 sc/qa/unit/data/functions/spreadsheet/fods/xlookup.fods |  607 ++--
 sc/source/core/data/queryiter.cxx   |  428 ---
 sc/source/core/tool/interpr1.cxx|   41 -
 sc/source/core/tool/rangecache.cxx  |  172 ++--
 6 files changed, 914 insertions(+), 385 deletions(-)

New commits:
commit 18ca62ab83a93dd7616c7e5204d3ddce525120b8
Author: Balazs Varga 
AuthorDate: Fri Apr 26 16:27:43 2024 +0200
Commit: Michael Meeks 
CommitDate: Wed May 22 08:15:48 2024 +0200

Related: tdf#160725 - Add horizontal binary search mode for SortedCache

and ScSortedRangeCache classes to support binary search mode in case of
different columns. Which is used by the new XLOOKUP function from now on
in case of binary search mode.

Conflicts:
sc/source/core/data/queryiter.cxx
sc/source/core/tool/rangecache.cxx

Change-Id: Ibb2ae33670cbe9b47110de57afb6376cd829b465
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166758
Tested-by: Jenkins
Reviewed-by: Balazs Varga 
(cherry picked from commit 85f733a9242339d8e92f992ff1ad6d1b99d3f383)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167915
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Michael Meeks 

diff --git a/sc/inc/queryiter.hxx b/sc/inc/queryiter.hxx
index 571b90a17475..ef84420431f2 100644
--- a/sc/inc/queryiter.hxx
+++ b/sc/inc/queryiter.hxx
@@ -89,9 +89,9 @@ protected:
 SCROW   nRow;
 
 class NonEmptyCellIndexer;
-typedef std::pair BinarySearchCellType;
-static NonEmptyCellIndexer MakeBinarySearchIndexer(const 
sc::CellStoreType& rCells,
-SCROW nStartRow, SCROW nEndRow);
+typedef std::pair BinarySearchCellType;
+static NonEmptyCellIndexer MakeBinarySearchIndexer(const 
sc::CellStoreType* pCells,
+SCCOLROW nStartRow, SCCOLROW nEndRow);
 };
 
 // The implementation using ScSortedRangeCache, which allows sorted iteration
@@ -108,6 +108,7 @@ protected:
 const ScQueryParam& rParam, bool bReverseSearch );
 void InitPosStart(sal_uInt8 nSortedBinarySearch = 0x00);
 void InitPosFinish( SCROW beforeRow, SCROW lastRow, bool bFirstMatch );
+void InitPosColFinish( SCCOL beforeCol, SCCOL lastCol, bool bFirstMatch );
 void IncPos() { IncPosImpl(); }
 bool IncPosFast() { return IncPosImpl(); }
 void IncBlock() { IncPos(); } // Cannot skip entire block, not linear.
@@ -133,9 +134,9 @@ protected:
 size_t sortedCachePosLast;
 
 class SortedCacheIndexer;
-typedef std::pair BinarySearchCellType;
-SortedCacheIndexer MakeBinarySearchIndexer(const sc::CellStoreType& rCells,
-SCROW nStartRow, SCROW nEndRow);
+typedef std::pair BinarySearchCellType;
+SortedCacheIndexer MakeBinarySearchIndexer(const sc::CellStoreType* pCells,
+SCCOLROW nStartRow, SCCOLROW nEndRow);
 };
 
 // Data and functionality for specific types of query.
@@ -210,16 +211,16 @@ protected:
 // and return if HandleItemFound() returns true.
 void PerformQuery();
 
-/* Only works if no regular expression is involved, only searches for rows 
in one column,
-   and only the first query entry is considered with simple conditions 
SC_LESS,SC_LESS_EQUAL,
-   SC_EQUAL (sorted ascending) or SC_GREATER,SC_GREATER_EQUAL (sorted 
descending). It
-   delivers a starting point set to nRow, i.e. the last row that either 
matches the searched
-   for value, or the last row that matches the condition. Continue with 
e.g. GetThis() and
-   GetNext() afterwards. Returns false if the searched for value is not in 
the search range
-   or if the range is not properly sorted, with nRow in that case set to 
the first row or after
-   the last row. In that case use GetFirst().
+/* Only works if no regular expression is involved, only searches for rows 
in one column or
+   only searches for cols in one row, and only the first query entry is 
considered with simple
+   conditions SC_LESS,SC_LESS_EQUAL, SC_EQUAL (sorted ascending) or 
SC_GREATER,SC_GREATER_EQUAL
+   (sorted descending). It delivers a starting point set to nRow/nCol, 
i.e. the last row/col that
+   either matches the searched for value, or the last row/col that matches 
the condition.
+   Continue with e.g. GetThis() and GetNext() afterwards. Returns false if 
the searched for value
+   is not in the search range or if the range is not properly sorted, with 
nRow/nCol in that case
+   set to the first row or after the last row. In that case use GetFirst().
 */
-bool BinarySearch( SCCOL col, bool forEqual = false );
+bool BinarySearch( SCCOLROW col_row, bool forEqual = false );
 
 /** If set, iterator stops on first non-matching cell
 content. May 

core.git: Branch 'distro/collabora/co-24.04' - sc/inc sc/qa sc/source

2024-05-22 Thread Balazs Varga (via logerrit)
 sc/inc/document.hxx |2 
 sc/inc/queryiter.hxx|2 
 sc/inc/rangecache.hxx   |3 
 sc/qa/unit/data/functions/spreadsheet/fods/xlookup.fods |  678 +++-
 sc/source/core/data/documen2.cxx|4 
 sc/source/core/data/queryiter.cxx   |   79 -
 sc/source/core/tool/interpr1.cxx|9 
 sc/source/core/tool/rangecache.cxx  |   43 -
 8 files changed, 384 insertions(+), 436 deletions(-)

New commits:
commit 0f9a36e514b55792d4e4cdb868a01bb7ff69498f
Author: Balazs Varga 
AuthorDate: Sun Apr 21 13:39:58 2024 +0200
Commit: Michael Meeks 
CommitDate: Wed May 22 08:14:24 2024 +0200

tdf#160725 - Fix XLOOKUP has different result for approximate

search than Excel.

Some rework for xlookup binary search in rows to get the correct results
when we are searching with binary mode in rows.

Change-Id: I7ef710c4ae638e2cf5d4bee45810cec7057f5d4b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166451
Reviewed-by: Balazs Varga 
Tested-by: Jenkins
(cherry picked from commit e2c9d38d95a1a0b5cf754fb04f2fd73c6ddb8004)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167914
Reviewed-by: Michael Meeks 
Tested-by: Jenkins CollaboraOffice 

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 468f0571c79f..52fd5a4a509f 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1404,7 +1404,7 @@ public:
 doesn't already exist. */
 ScLookupCache & GetLookupCache( const ScRange & rRange, 
ScInterpreterContext* pContext );
 ScSortedRangeCache & GetSortedRangeCache( const ScRange & rRange, const 
ScQueryParam& param,
-  ScInterpreterContext* pContext );
+  ScInterpreterContext* pContext, 
sal_uInt8 nSortedBinarySearch = 0x00 );
 /** Only ScLookupCache dtor uses RemoveLookupCache(), do
 not use elsewhere! */
 voidRemoveLookupCache( ScLookupCache & rCache );
diff --git a/sc/inc/queryiter.hxx b/sc/inc/queryiter.hxx
index f494b83d74a5..571b90a17475 100644
--- a/sc/inc/queryiter.hxx
+++ b/sc/inc/queryiter.hxx
@@ -106,7 +106,7 @@ public:
 protected:
 ScQueryCellIteratorAccessSpecific( ScDocument& rDocument, 
ScInterpreterContext& rContext,
 const ScQueryParam& rParam, bool bReverseSearch );
-void InitPosStart();
+void InitPosStart(sal_uInt8 nSortedBinarySearch = 0x00);
 void InitPosFinish( SCROW beforeRow, SCROW lastRow, bool bFirstMatch );
 void IncPos() { IncPosImpl(); }
 bool IncPosFast() { return IncPosImpl(); }
diff --git a/sc/inc/rangecache.hxx b/sc/inc/rangecache.hxx
index c65e8653a458..bca9554a5e6a 100644
--- a/sc/inc/rangecache.hxx
+++ b/sc/inc/rangecache.hxx
@@ -46,7 +46,8 @@ class ScSortedRangeCache final : public SvtListener
 public:
 /// MUST be new'd because Notify() deletes.
 ScSortedRangeCache(ScDocument* pDoc, const ScRange& rRange, const 
ScQueryParam& param,
-   ScInterpreterContext* context, bool invalid = false);
+   ScInterpreterContext* context, bool invalid = false,
+   sal_uInt8 nSortedBinarySearch = 0x00);
 
 /// Returns if the cache is usable.
 bool isValid() const { return mValid; }
diff --git a/sc/qa/unit/data/functions/spreadsheet/fods/xlookup.fods 
b/sc/qa/unit/data/functions/spreadsheet/fods/xlookup.fods
index 8da1a44240bd..41a5789f73a1 100644
--- a/sc/qa/unit/data/functions/spreadsheet/fods/xlookup.fods
+++ b/sc/qa/unit/data/functions/spreadsheet/fods/xlookup.fods
@@ -1,7 +1,7 @@
 
 
 http://openoffice.org/2004/office; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:xlink="http://www.w3.org/1999/xlink; 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:dc="http://purl.org/dc/elements/1.1/; 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:rpt="http://openoffice.org/2005/report; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:ooow="http://openoffice.org/200
 4/writer" xmlns:oooc="http://openoffice.org/2004/calc; 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:xforms="http://www.w3.org/2002/xforms; 
xmlns:tableooo="http://openoffice.org/2009/table; 

core.git: Branch 'distro/collabora/co-24.04' - sc/inc sc/qa sc/source

2024-03-04 Thread Caolán McNamara (via logerrit)
 sc/inc/docoptio.hxx  |4 -
 sc/inc/funcuno.hxx   |1 
 sc/inc/optuno.hxx|9 +---
 sc/inc/scmod.hxx |4 -
 sc/qa/unit/tiledrendering/tiledrendering.cxx |   30 --
 sc/source/core/data/docpool.cxx  |3 -
 sc/source/core/tool/docoptio.cxx |1 
 sc/source/ui/app/inputhdl.cxx|2 
 sc/source/ui/app/scmod.cxx   |   45 +++--
 sc/source/ui/docshell/docsh3.cxx |4 -
 sc/source/ui/docshell/docsh4.cxx |4 -
 sc/source/ui/inc/tabview.hxx |1 
 sc/source/ui/unoobj/docuno.cxx   |   57 ++-
 sc/source/ui/unoobj/funcuno.cxx  |   42 ++-
 sc/source/ui/unoobj/optuno.cxx   |   28 -
 sc/source/ui/view/gridwin4.cxx   |   18 +++-
 sc/source/ui/view/tabview.cxx|   29 ++---
 sc/source/ui/view/tabvwsh4.cxx   |2 
 sc/source/ui/view/viewdata.cxx   |3 -
 sc/source/ui/view/viewfun2.cxx   |6 +-
 20 files changed, 170 insertions(+), 123 deletions(-)

New commits:
commit 483fedd15bb801815c6ab62de329f4fd91889c31
Author: Caolán McNamara 
AuthorDate: Fri Feb 23 21:12:15 2024 +
Commit: Miklos Vajna 
CommitDate: Mon Mar 4 14:41:16 2024 +0100

move inline spelling setting out of document and into viewshell

like what writer does, so one view of a document can have spelling
enabled and another disabled

Change-Id: I9eae02fd1a2def56bfa9399860e416180fc178c4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164106
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sc/inc/docoptio.hxx b/sc/inc/docoptio.hxx
index 6e4d4f124cda..80c5654efeca 100644
--- a/sc/inc/docoptio.hxx
+++ b/sc/inc/docoptio.hxx
@@ -39,7 +39,6 @@ class SC_DLLPUBLIC ScDocOptions
 bool   bIsIter; ///< iterations for circular refs
 bool   bCalcAsShown;///< calculate as shown (wrt precision)
 bool   bMatchWholeCell; ///< search criteria must match the 
whole cell
-bool   bDoAutoSpell;///< auto-spelling
 bool   bLookUpColRowNames;  ///< determine column-/row titles 
automagically
 mutable bool bFormulaRegexEnabled;///< regular expressions in formulas 
enabled, only when reading settings
 mutable bool bFormulaWildcardsEnabled;///< wildcards in formulas enabled, 
only when reading settings
@@ -50,8 +49,6 @@ public:
 
 bool   IsLookUpColRowNames() const   { return bLookUpColRowNames; }
 void   SetLookUpColRowNames( bool bVal ) { bLookUpColRowNames = bVal; }
-bool   IsAutoSpell() const  { return bDoAutoSpell; }
-void   SetAutoSpell( bool bVal ){ bDoAutoSpell = bVal; }
 bool   IsMatchWholeCell() const { return bMatchWholeCell; }
 void   SetMatchWholeCell( bool bVal )   { bMatchWholeCell = bVal; }
 bool   IsIgnoreCase() const { return bIsIgnoreCase; }
@@ -116,7 +113,6 @@ inline bool ScDocOptions::operator==( const ScDocOptions& 
rOpt ) const
 &&  rOpt.nTabDistance   == nTabDistance
 &&  rOpt.bCalcAsShown   == bCalcAsShown
 &&  rOpt.bMatchWholeCell== bMatchWholeCell
-&&  rOpt.bDoAutoSpell   == bDoAutoSpell
 &&  rOpt.bLookUpColRowNames == bLookUpColRowNames
 &&  rOpt.bFormulaRegexEnabled   == bFormulaRegexEnabled
 &&  rOpt.bFormulaWildcardsEnabled == bFormulaWildcardsEnabled
diff --git a/sc/inc/funcuno.hxx b/sc/inc/funcuno.hxx
index 3d62ecaded9d..912201ac4bb7 100644
--- a/sc/inc/funcuno.hxx
+++ b/sc/inc/funcuno.hxx
@@ -64,6 +64,7 @@ private:
 SfxItemPropertyMap aPropertyMap;
 boolmbArray;
 boolmbValid;
+boolmbSpellOnline;
 
 public:
 ScFunctionAccess();
diff --git a/sc/inc/optuno.hxx b/sc/inc/optuno.hxx
index 72050044e363..27b0c3d6dc56 100644
--- a/sc/inc/optuno.hxx
+++ b/sc/inc/optuno.hxx
@@ -31,16 +31,13 @@
 #define PROP_UNO_LOOKUPLABELS   7
 #define PROP_UNO_MATCHWHOLE 8
 #define PROP_UNO_NULLDATE   9
-#define PROP_UNO_SPELLONLINE10
-#define PROP_UNO_STANDARDDEC11
-#define PROP_UNO_REGEXENABLED   12
-#define PROP_UNO_WILDCARDSENABLED 13
+#define PROP_UNO_STANDARDDEC10
+#define PROP_UNO_REGEXENABLED   11
+#define PROP_UNO_WILDCARDSENABLED 12
 
 class ScDocOptionsHelper
 {
 public:
-static std::span GetPropertyMap();
-
 static bool setPropertyValue( ScDocOptions& rOptions,
 const SfxItemPropertyMap& rPropMap,
 std::u16string_view aPropertyName,
diff --git a/sc/inc/scmod.hxx b/sc/inc/scmod.hxx
index f95da4a46280..18705e6189f0 

core.git: Branch 'distro/collabora/co-24.04' - sc/inc sc/qa sc/source

2024-02-06 Thread Caolán McNamara (via logerrit)
 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 b77d256b96c5cfb34fa953b3ffc64c664b2a7743
Author: Caolán McNamara 
AuthorDate: Thu Feb 1 12:47:53 2024 +
Commit: Caolán McNamara 
CommitDate: Tue Feb 6 18:11:54 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" (which was just one case, the case that now passes
TopLeftTileRow, nBottomRightTileRow.

When hint is true limit to max of 1024 rows, and the apparent case
is visible in ScGridWindow::UpdateFormulaRange at

https://github.com/CollaboraOnline/online/issues/6893#issuecomment-1921141048

Change-Id: Iebe890c3ac967800b60150aaa71f7e845a021f60
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162875
Reviewed-by: Szymon Kłos 
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Noel Grandin 
Reviewed-by: Caolán McNamara 
(cherry picked from commit e4410bd37fc018c851b5ebf9cf011d59af6a2ad9)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163016

diff --git a/sc/inc/fillinfo.hxx b/sc/inc/fillinfo.hxx
index 30e4b7540a67..68f845df42fa 100644
--- a/sc/inc/fillinfo.hxx
+++ b/sc/inc/fillinfo.hxx
@@ -268,7 +268,7 @@ struct ScTableInfo
 SCSIZE  mnArrCapacity;
 boolmbPageMode;
 
-explicitScTableInfo(SCROW nStartRow, SCROW nEndRow);
+explicitScTableInfo(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 1b7480b2fc9a..53072640324e 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 e9fef2c0cf08..4f643a04dae3 100644
--- a/sc/source/core/data/fillinfo.cxx
+++ b/sc/source/core/data/fillinfo.cxx
@@ -1071,14 +1071,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_WARN("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 cd7841a059a7..c85d57774e00 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, 

core.git: Branch 'distro/collabora/co-24.04' - sc/inc sc/qa sc/source

2024-01-20 Thread Noel Grandin (via logerrit)
 sc/inc/fillinfo.hxx |2 +-
 sc/qa/unit/ucalc_condformat.cxx |2 +-
 sc/source/core/data/fillinfo.cxx|   13 -
 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, 18 insertions(+), 15 deletions(-)

New commits:
commit 382d0d417c88b47c546a000921596d88d811d073
Author: Noel Grandin 
AuthorDate: Fri Jan 19 14:27:10 2024 +0200
Commit: Noel Grandin 
CommitDate: Sat Jan 20 12:36:01 2024 +0100

cool#6893 reduce allocation in ScGridWindow::PaintTile

the code is needlessly allocating way more rows than we need, especially
when we have page to the bottom of a large document.

Make it so we allocate exactly the number of rows we need, instead
of allocating a default large number of rows (1024).

Which reveals that we need to allocate two extra rows, not sure why.

Change-Id: I9ca38f2712480ee8c0c3254061c92e457e328416
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162277
Reviewed-by: Michael Meeks 
Tested-by: Noel Grandin 
Reviewed-by: Noel Grandin 

diff --git a/sc/inc/fillinfo.hxx b/sc/inc/fillinfo.hxx
index 81086ed358ba..30e4b7540a67 100644
--- a/sc/inc/fillinfo.hxx
+++ b/sc/inc/fillinfo.hxx
@@ -268,7 +268,7 @@ struct ScTableInfo
 SCSIZE  mnArrCapacity;
 boolmbPageMode;
 
-explicitScTableInfo(const SCSIZE capacity = 1024);
+explicitScTableInfo(SCROW nStartRow, SCROW nEndRow);
 ~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 7a0abc7cf026..1b7480b2fc9a 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;
+ScTableInfo aTabInfo(0, 2);
 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 4a573e1c21da..b2c0fc374b04 100644
--- a/sc/source/core/data/fillinfo.cxx
+++ b/sc/source/core/data/fillinfo.cxx
@@ -1069,13 +1069,16 @@ void ScDocument::FillInfo(
 rArray.MirrorSelfX();
 }
 
-ScTableInfo::ScTableInfo(const SCSIZE capacity)
-: mpRowInfo(new RowInfo[capacity])
-, mnArrCount(0)
-, mnArrCapacity(capacity)
+/// We seem to need to allocate two extra rows here, not sure why
+///
+ScTableInfo::ScTableInfo(SCROW nStartRow, SCROW nEndRow)
+: mnArrCount(0)
+, mnArrCapacity(nEndRow - nStartRow + 3)
 , mbPageMode(false)
 {
-memset(static_cast(mpRowInfo.get()), 0, mnArrCapacity * 
sizeof(RowInfo));
+assert(nStartRow >= 0);
+assert(nEndRow >= nStartRow);
+mpRowInfo.reset(new RowInfo[nEndRow - nStartRow + 3] {});
 }
 
 ScTableInfo::~ScTableInfo()
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index e2c6b4b27949..cd7841a059a7 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;
+ScTableInfo aTabInfo(nY1, nY2);
 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 649f85bfc1a2..2ad901f4b110 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;
+ScTableInfo aTableInfo(mnFirstVisibleRow, nMaxVisibleRow);
 mpDoc->FillInfo(aTableInfo, mnFirstVisibleCol, mnFirstVisibleRow, 
nMaxVisibleCol, nMaxVisibleRow, 0, 0.0, 0.0, false, false);
 ScOutputData aOutput(, 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 186243702985..6c6b915f51df