tdf#126109 calc slow when replacing string to number
retain the column block iterator array during the process, shaves 20%
off the time
Change-Id: Id492cf142ecc34af6fd236135d87f49b5a630d5e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135855
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
(cherry picked from commit 1cc9f4d972f8a5e1e3f4980942e128dee9a2701c)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135877
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 1a0a0e4..da93ac7 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -1188,7 +1188,8 @@ private:
const ScMarkData& rMark, OUString& rUndoStr, ScDocument* pUndoDoc);
bool Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
SCCOL nLastCol, SCROW nLastRow,
const ScMarkData& rMark, OUString& rUndoStr, ScDocument* pUndoDoc);
const ScMarkData& rMark, OUString& rUndoStr, ScDocument* pUndoDoc,
std::vector< sc::ColumnBlockConstPosition >& blockPos);
bool SearchAll(const SvxSearchItem& rSearchItem, const ScMarkData& rMark,
ScRangeList& rMatchedRanges, OUString& rUndoStr, ScDocument* pUndoDoc);
bool Replace(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
diff --git a/sc/source/core/data/table6.cxx b/sc/source/core/data/table6.cxx
index 0ced569..966b449 100644
--- a/sc/source/core/data/table6.cxx
+++ b/sc/source/core/data/table6.cxx
@@ -323,12 +323,14 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
GetCellArea( nLastCol, nLastRow);
else
GetLastDataPos(nLastCol, nLastRow);
return Search(rSearchItem, rCol, rRow, nLastCol, nLastRow, rMark, rUndoStr, pUndoDoc);
std::vector< sc::ColumnBlockConstPosition > blockPos;
return Search(rSearchItem, rCol, rRow, nLastCol, nLastRow, rMark, rUndoStr, pUndoDoc, blockPos);
}
bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
SCCOL nLastCol, SCROW nLastRow,
const ScMarkData& rMark, OUString& rUndoStr, ScDocument* pUndoDoc)
const ScMarkData& rMark, OUString& rUndoStr, ScDocument* pUndoDoc,
std::vector< sc::ColumnBlockConstPosition >& blockPos)
{
bool bFound = false;
bool bAll = (rSearchItem.GetCommand() == SvxSearchCmd::FIND_ALL)
@@ -339,9 +341,12 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
bool bSkipFiltered = !rSearchItem.IsSearchFiltered();
bool bSearchNotes = (rSearchItem.GetCellType() == SvxSearchCellType::NOTE);
// We need to cache sc::ColumnBlockConstPosition per each column.
std::vector< sc::ColumnBlockConstPosition > blockPos( nLastCol + 1 );
for( SCCOL i = 0; i <= nLastCol; ++i )
aCol[ i ].InitBlockPosition( blockPos[ i ] );
if (static_cast<SCCOL>(blockPos.size()) != nLastCol + 1)
{
blockPos.resize( nLastCol + 1 );
for( SCCOL i = 0; i <= nLastCol; ++i )
aCol[ i ].InitBlockPosition( blockPos[ i ] );
}
if (!bAll && rSearchItem.GetBackward())
{
SCROW nLastNonFilteredRow = rDocument.MaxRow() + 1;
@@ -529,9 +534,10 @@ bool ScTable::SearchAll(const SvxSearchItem& rSearchItem, const ScMarkData& rMar
else
GetLastDataPos(nLastCol, nLastRow);
std::vector< sc::ColumnBlockConstPosition > blockPos;
do
{
bFound = Search(rSearchItem, nCol, nRow, nLastCol, nLastRow, rMark, rUndoStr, pUndoDoc);
bFound = Search(rSearchItem, nCol, nRow, nLastCol, nLastRow, rMark, rUndoStr, pUndoDoc, blockPos);
if (bFound)
{
bEverFound = true;
@@ -595,10 +601,11 @@ bool ScTable::ReplaceAll(
SvxSearchItem aCopyItem(rSearchItem);
aCopyItem.SetRowDirection(false);
std::vector< sc::ColumnBlockConstPosition > blockPos;
bool bEverFound = false;
while (true)
{
bool bFound = Search(aCopyItem, nCol, nRow, nLastCol, nLastRow, rMark, rUndoStr, pUndoDoc);
bool bFound = Search(aCopyItem, nCol, nRow, nLastCol, nLastRow, rMark, rUndoStr, pUndoDoc, blockPos);
if (bFound)
{