sc/source/core/data/table3.cxx |   38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

New commits:
commit 02f3157f75b654ef7648efdc3004b3f326d5af40
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Tue Nov 23 13:09:40 2021 +0100
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Thu Nov 25 14:26:26 2021 +0100

    don't fetch cell string content for each query item (tdf#133804)
    
    When using autofilter, the query entry can have thousands of items,
    and fetching of the cell string value is not trivial in some cases.
    
    I'm not doing this for numeric values, as those depend on query
    items and also seem fairly fast.
    
    Change-Id: I01fa2e0cbce8f770d1ed079c0dba74830402a895
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125735
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index c8ba5c882234..49c075121b61 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -2561,9 +2561,8 @@ public:
         return std::pair<bool,bool>(bOk, bTestEqual);
     }
 
-    std::pair<bool,bool> compareByString(
-        const ScRefCellValue& rCell, SCROW nRow, const ScQueryEntry& rEntry, 
const ScQueryEntry::Item& rItem,
-        const ScInterpreterContext* pContext)
+    OUString getCellString(const ScRefCellValue& rCell, SCROW nRow, const 
ScQueryEntry& rEntry,
+        const ScInterpreterContext* pContext, const svl::SharedString** 
sharedString)
     {
         if (rCell.meType == CELLTYPE_FORMULA && rCell.mpFormula->GetErrCode() 
!= FormulaError::NONE)
         {
@@ -2579,33 +2578,27 @@ public:
                     assert(pos.second); // inserted
                     it = pos.first;
                 }
-                const svl::SharedString& sharedError = it->second;
-                return compareByStringComparator(rEntry, rItem, &sharedError, 
nullptr);
+                *sharedString = &it->second;
+                return OUString();
             }
-            const OUString aCellStr = 
ScGlobal::GetErrorString(rCell.mpFormula->GetErrCode());
-            return compareByStringComparator(rEntry, rItem, nullptr, 
&aCellStr);
+            return ScGlobal::GetErrorString(rCell.mpFormula->GetErrCode());
         }
         else if (rCell.meType == CELLTYPE_STRING)
         {
-            return compareByStringComparator(rEntry, rItem, rCell.mpString, 
nullptr);
+            *sharedString = rCell.mpString;
+            return OUString();
         }
         else
         {
             sal_uInt32 nFormat = pContext ? mrTab.GetNumberFormat( *pContext, 
ScAddress(static_cast<SCCOL>(rEntry.nField), nRow, mrTab.GetTab()) ) :
                 mrTab.GetNumberFormat( static_cast<SCCOL>(rEntry.nField), nRow 
);
             SvNumberFormatter* pFormatter = pContext ? 
pContext->GetFormatTable() : mrDoc.GetFormatTable();
-            const svl::SharedString* sharedString = nullptr;
-            OUString aStr = ScCellFormat::GetInputString(rCell, nFormat, 
*pFormatter, mrDoc, &sharedString, rEntry.bDoQuery);
-            // Use the shared string for less conversions, if available.
-            if( sharedString != nullptr )
-                return compareByStringComparator(rEntry, rItem, sharedString, 
nullptr);
-            return compareByStringComparator(rEntry, rItem, nullptr, &aStr);
+            return ScCellFormat::GetInputString(rCell, nFormat, *pFormatter, 
mrDoc, sharedString, rEntry.bDoQuery);
         }
     }
 
-    // Called from compareByString() method, where different sources of 
strings are checked.
     // The value is placed inside one parameter: [pValueSource1] or 
[pValueSource2] but never in both.
-    std::pair<bool,bool> compareByStringComparator(const ScQueryEntry& rEntry, 
const ScQueryEntry::Item& rItem,
+    std::pair<bool,bool> compareByString(const ScQueryEntry& rEntry, const 
ScQueryEntry::Item& rItem,
         const svl::SharedString* pValueSource1, const OUString * pValueSource2)
     {
         bool bOk = false;
@@ -2960,6 +2953,9 @@ std::pair<bool,bool> validQueryProcessEntry(SCROW nRow, 
SCCOL nCol, SCTAB nTab,
         return aRes;
     }
     // Generic handling.
+    const svl::SharedString* cellSharedString = nullptr;
+    OUString cellString;
+    bool cellStringSet = false;
     for (const auto& rItem : rItems)
     {
         if (rItem.meType == ScQueryEntry::ByTextColor)
@@ -2985,8 +2981,14 @@ std::pair<bool,bool> validQueryProcessEntry(SCROW nRow, 
SCCOL nCol, SCTAB nTab,
         }
         else if (QueryEvaluator::isQueryByString(rEntry, rItem, aCell))
         {
-            std::pair<bool,bool> aThisRes =
-                aEval.compareByString(aCell, nRow, rEntry, rItem, pContext);
+            if(!cellStringSet)
+            {
+                cellString = aEval.getCellString(aCell, nRow, rEntry, 
pContext, &cellSharedString);
+                cellStringSet = true;
+            }
+            std::pair<bool,bool> aThisRes = cellSharedString
+                ? aEval.compareByString(rEntry, rItem, cellSharedString, 
nullptr)
+                : aEval.compareByString(rEntry, rItem, nullptr, &cellString);
             aRes.first |= aThisRes.first;
             aRes.second |= aThisRes.second;
         }

Reply via email to