sc/inc/table.hxx               |    3 ++-
 sc/source/core/data/table6.cxx |   21 ++++++++++++++-------
 2 files changed, 16 insertions(+), 8 deletions(-)

New commits:
commit ceb5b35ca0677375e05f0acd02934045e013c04d
Author:     Noel Grandin <[email protected]>
AuthorDate: Tue Jun 14 18:44:02 2022 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Wed Jun 15 12:24:36 2022 +0200

    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 <[email protected]>
    (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 1a0a0e477758..da93ac71c25e 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 0ced56900d6d..966b4491c348 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)
         {

Reply via email to