sc/source/core/data/queryiter.cxx |   27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

New commits:
commit 18eeb85d4899fa8e4a2b1a84fc4a32c3a94f7640
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Fri May 6 14:08:47 2022 +0200
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Wed May 11 11:47:47 2022 +0200

    keep only a reference to a vector if equal to what's wanted
    
    This avoids copying the data repeatedly.
    
    Change-Id: Id3fadf8414c66143e12261a14b75b984415ed9a2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134121
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/sc/source/core/data/queryiter.cxx 
b/sc/source/core/data/queryiter.cxx
index 7d2b980004d2..184e86ada37a 100644
--- a/sc/source/core/data/queryiter.cxx
+++ b/sc/source/core/data/queryiter.cxx
@@ -1054,20 +1054,35 @@ void ScQueryCellIteratorAccessSpecific< 
ScQueryCellIteratorAccess::SortedCache >
 // Rows in the given range are kept in a sorted vector and that vector is 
binary-searched.
 class ScQueryCellIteratorAccessSpecific< 
ScQueryCellIteratorAccess::SortedCache >::SortedCacheIndexer
 {
-    std::vector<SCROW> mSortedRows;
+    std::vector<SCROW> mSortedRowsCopy;
+    const std::vector<SCROW>& mSortedRows;
     const sc::CellStoreType& mCells;
     size_t mLowIndex;
     size_t mHighIndex;
     bool mValid;
+
+    const std::vector<SCROW>& makeSortedRows( const ScSortedRangeCache* cache, 
SCROW startRow, SCROW endRow )
+    {
+        // Keep a reference to rows from the cache if equal, otherwise make a 
copy.
+        if(startRow == cache->getRange().aStart.Row() && endRow == 
cache->getRange().aEnd.Row())
+            return cache->sortedRows();
+        else
+        {
+            mSortedRowsCopy.reserve( cache->sortedRows().size());
+            for( SCROW row : cache->sortedRows())
+                if( row >= startRow && row <= endRow )
+                    mSortedRowsCopy.emplace_back( row );
+            return mSortedRowsCopy;
+        }
+    }
+
 public:
     SortedCacheIndexer( const sc::CellStoreType& cells, SCROW startRow, SCROW 
endRow,
         const ScSortedRangeCache* cache )
-        : mCells( cells ), mValid( false )
+        : mSortedRows( makeSortedRows( cache, startRow, endRow ))
+        , mCells( cells )
+        , mValid( false )
     {
-        mSortedRows.reserve( cache->sortedRows().size());
-        for( SCROW row : cache->sortedRows())
-            if( row >= startRow && row <= endRow )
-                mSortedRows.emplace_back( row );
         if(mSortedRows.empty())
             return;
         mLowIndex = 0;

Reply via email to