summaryrefslogtreecommitdiff
path: root/sc/source/core
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2021-11-23 13:09:40 +0100
committerLuboš Luňák <l.lunak@collabora.com>2021-11-25 14:26:26 +0100
commit02f3157f75b654ef7648efdc3004b3f326d5af40 (patch)
tree363fe1aad0fefa34a4f594975af2ef8910905e48 /sc/source/core
parent98acc3d926571c13305501806ebc1b8be85e8960 (diff)
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.lunak@collabora.com>
Diffstat (limited to 'sc/source/core')
-rw-r--r--sc/source/core/data/table3.cxx38
1 files changed, 20 insertions, 18 deletions
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;
}