diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-04-03 13:21:46 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-04-03 17:50:31 +0200 |
commit | 3c10a1a4ce65496877d8fc78359f9b7e59d2703c (patch) | |
tree | 75b862e562550813441ba3e72bb34ab9513bff7b | |
parent | 61337efb8c6a434a88a82dd2819edf600e867aa4 (diff) |
reduce cost of displaying sheets with conditional formatting
shaves off 1-2% of the cost by stack-allocating some iterator objects
Change-Id: I509d4de6c59db086f112d83768a24c11dd5d0872
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165745
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | sc/inc/column.hxx | 3 | ||||
-rw-r--r-- | sc/inc/dociter.hxx | 11 | ||||
-rw-r--r-- | sc/source/core/data/column3.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/dociter.cxx | 34 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 4 |
5 files changed, 24 insertions, 32 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index e8dec1fb437a..39b192bb68ef 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -26,6 +26,7 @@ #include "rangelst.hxx" #include "types.hxx" #include "mtvelements.hxx" +#include "attarray.hxx" #include <formula/types.hxx> #include <svl/zforlist.hxx> #include <svx/svdobj.hxx> @@ -165,7 +166,7 @@ public: bool HasAttrib( SCROW nRow1, SCROW nRow2, HasAttrFlags nMask ) const; bool HasAttrib( SCROW nRow, HasAttrFlags nMask, SCROW* nStartRow = nullptr, SCROW* nEndRow = nullptr ) const; - std::unique_ptr<ScAttrIterator> CreateAttrIterator( SCROW nStartRow, SCROW nEndRow ) const; + ScAttrIterator CreateAttrIterator( SCROW nStartRow, SCROW nEndRow ) const; bool IsAllAttrEqual( const ScColumnData& rCol, SCROW nStartRow, SCROW nEndRow ) const; diff --git a/sc/inc/dociter.hxx b/sc/inc/dociter.hxx index 6be5a77e5e5b..190d284a39e8 100644 --- a/sc/inc/dociter.hxx +++ b/sc/inc/dociter.hxx @@ -26,12 +26,14 @@ #include "cellvalue.hxx" #include "mtvelements.hxx" #include "queryparam.hxx" +#include "attarray.hxx" #include <vcl/outdev.hxx> #include <vcl/vclptr.hxx> #include <memory> #include <set> #include <vector> +#include <optional> class ScDocument; class ScPatternAttr; @@ -255,13 +257,11 @@ private: SCROW nStartRow; SCROW nEndRow; SCCOL nCol; - std::unique_ptr<ScAttrIterator> - pColIter; + std::optional<ScAttrIterator> moColIter; public: ScDocAttrIterator(ScDocument& rDocument, SCTAB nTable, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2); - ~ScDocAttrIterator(); const ScPatternAttr* GetNext( SCCOL& rCol, SCROW& rRow1, SCROW& rRow2 ); }; @@ -277,13 +277,12 @@ private: SCROW nEndRow; SCCOL nIterStartCol; SCCOL nIterEndCol; - std::unique_ptr<ScAttrIterator> - pColIter; + std::optional<ScAttrIterator> + moColIter; public: ScAttrRectIterator(ScDocument& rDocument, SCTAB nTable, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2); - ~ScAttrRectIterator(); void DataChanged(); const ScPatternAttr* GetNext( SCCOL& rCol1, SCCOL& rCol2, SCROW& rRow1, SCROW& rRow2 ); diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 047ebddd81b0..e7a971e8c613 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -2042,9 +2042,9 @@ void ScColumn::MixData( CellStorageModified(); } -std::unique_ptr<ScAttrIterator> ScColumnData::CreateAttrIterator( SCROW nStartRow, SCROW nEndRow ) const +ScAttrIterator ScColumnData::CreateAttrIterator( SCROW nStartRow, SCROW nEndRow ) const { - return std::make_unique<ScAttrIterator>( pAttrArray.get(), nStartRow, nEndRow, &GetDoc().getCellAttributeHelper().getDefaultCellAttribute() ); + return ScAttrIterator( pAttrArray.get(), nStartRow, nEndRow, &GetDoc().getCellAttributeHelper().getDefaultCellAttribute() ); } namespace { diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx index aa37dc8a8199..00309ceb871b 100644 --- a/sc/source/core/data/dociter.cxx +++ b/sc/source/core/data/dociter.cxx @@ -1580,18 +1580,14 @@ ScDocAttrIterator::ScDocAttrIterator(ScDocument& rDocument, SCTAB nTable, nCol( nCol1 ) { if ( ValidTab(nTab) && nTab < rDoc.GetTableCount() && rDoc.maTabs[nTab] ) - pColIter = rDoc.maTabs[nTab]->GetColumnData(nCol).CreateAttrIterator( nStartRow, nEndRow ); -} - -ScDocAttrIterator::~ScDocAttrIterator() -{ + moColIter = rDoc.maTabs[nTab]->GetColumnData(nCol).CreateAttrIterator( nStartRow, nEndRow ); } const ScPatternAttr* ScDocAttrIterator::GetNext( SCCOL& rCol, SCROW& rRow1, SCROW& rRow2 ) { - while ( pColIter ) + while ( moColIter ) { - const ScPatternAttr* pPattern = pColIter->Next( rRow1, rRow2 ); + const ScPatternAttr* pPattern = moColIter->Next( rRow1, rRow2 ); if ( pPattern ) { rCol = nCol; @@ -1600,9 +1596,9 @@ const ScPatternAttr* ScDocAttrIterator::GetNext( SCCOL& rCol, SCROW& rRow1, SCRO ++nCol; if ( nCol <= nEndCol ) - pColIter = rDoc.maTabs[nTab]->GetColumnData(nCol).CreateAttrIterator( nStartRow, nEndRow ); + moColIter = rDoc.maTabs[nTab]->GetColumnData(nCol).CreateAttrIterator( nStartRow, nEndRow ); else - pColIter.reset(); + moColIter.reset(); } return nullptr; // Nothing anymore } @@ -1712,7 +1708,7 @@ ScAttrRectIterator::ScAttrRectIterator(ScDocument& rDocument, SCTAB nTable, { if ( ValidTab(nTab) && nTab < rDoc.GetTableCount() && rDoc.maTabs[nTab] ) { - pColIter = rDoc.maTabs[nTab]->GetColumnData(nIterStartCol).CreateAttrIterator( nStartRow, nEndRow ); + moColIter = rDoc.maTabs[nTab]->GetColumnData(nIterStartCol).CreateAttrIterator( nStartRow, nEndRow ); while ( nIterEndCol < nEndCol && rDoc.maTabs[nTab]->GetColumnData(nIterEndCol).IsAllAttrEqual( rDoc.maTabs[nTab]->GetColumnData(nIterEndCol+1), nStartRow, nEndRow ) ) @@ -1720,25 +1716,21 @@ ScAttrRectIterator::ScAttrRectIterator(ScDocument& rDocument, SCTAB nTable, } } -ScAttrRectIterator::~ScAttrRectIterator() -{ -} - void ScAttrRectIterator::DataChanged() { - if (pColIter) + if (moColIter) { - SCROW nNextRow = pColIter->GetNextRow(); - pColIter = rDoc.maTabs[nTab]->GetColumnData(nIterStartCol).CreateAttrIterator( nNextRow, nEndRow ); + SCROW nNextRow = moColIter->GetNextRow(); + moColIter = rDoc.maTabs[nTab]->GetColumnData(nIterStartCol).CreateAttrIterator( nNextRow, nEndRow ); } } const ScPatternAttr* ScAttrRectIterator::GetNext( SCCOL& rCol1, SCCOL& rCol2, SCROW& rRow1, SCROW& rRow2 ) { - while ( pColIter ) + while ( moColIter ) { - const ScPatternAttr* pPattern = pColIter->Next( rRow1, rRow2 ); + const ScPatternAttr* pPattern = moColIter->Next( rRow1, rRow2 ); if ( pPattern ) { rCol1 = nIterStartCol; @@ -1750,14 +1742,14 @@ const ScPatternAttr* ScAttrRectIterator::GetNext( SCCOL& rCol1, SCCOL& rCol2, if ( nIterStartCol <= nEndCol ) { nIterEndCol = nIterStartCol; - pColIter = rDoc.maTabs[nTab]->GetColumnData(nIterStartCol).CreateAttrIterator( nStartRow, nEndRow ); + moColIter = rDoc.maTabs[nTab]->GetColumnData(nIterStartCol).CreateAttrIterator( nStartRow, nEndRow ); while ( nIterEndCol < nEndCol && rDoc.maTabs[nTab]->GetColumnData(nIterEndCol).IsAllAttrEqual( rDoc.maTabs[nTab]->GetColumnData(nIterEndCol+1), nStartRow, nEndRow ) ) ++nIterEndCol; } else - pColIter.reset(); + moColIter.reset(); } return nullptr; // Nothing anymore } diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 7d03ef681016..aa51bec2d727 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1057,8 +1057,8 @@ void ScTable::TransposeColPatterns(ScTable* pTransClip, SCCOL nCol1, SCCOL nCol, SCROW nAttrRow1 = {}; // spurious -Werror=maybe-uninitialized SCROW nAttrRow2 = {}; // spurious -Werror=maybe-uninitialized const ScPatternAttr* pPattern; - std::unique_ptr<ScAttrIterator> pAttrIter(aCol[nCol].CreateAttrIterator( nRow1, nRow2 )); - while ( (pPattern = pAttrIter->Next( nAttrRow1, nAttrRow2 )) != nullptr ) + ScAttrIterator aAttrIter(aCol[nCol].CreateAttrIterator( nRow1, nRow2 )); + while ( (pPattern = aAttrIter.Next( nAttrRow1, nAttrRow2 )) != nullptr ) { // ptr compare OK, was so before if (&rDocument.getCellAttributeHelper().getDefaultCellAttribute() != pPattern) |