summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2021-11-08 17:29:41 +0100
committerLuboš Luňák <l.lunak@collabora.com>2021-11-08 20:34:23 +0100
commitec0edb0969c23b25576f4d1b3b2ee5d3f21990ad (patch)
treeb3ac7b7d55455e4dc0df4cf2348988f74ca1719a /sc/source
parent1a588c71a0b60d200077138eaff54fced14c4fe2 (diff)
optimize VLOOKUP by returning SharedString if possible (tdf#139444)
Profiling shows that the slowness mostly comes from converting the cell's SharedString to OUString and then the comparison converts it back. To improve performance, return the SharedString if possible and ignore the OUString. Change-Id: Idb190bd0354cea3185e5ff9ebaf92cab63f23f70 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124880 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/core/data/column3.cxx4
-rw-r--r--sc/source/core/data/document.cxx4
-rw-r--r--sc/source/core/data/table2.cxx4
-rw-r--r--sc/source/core/data/table3.cxx11
-rw-r--r--sc/source/core/tool/cellform.cxx17
5 files changed, 30 insertions, 10 deletions
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index dfc6b23a5fba..8361018c41c8 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -2996,10 +2996,10 @@ double* ScColumn::GetValueCell( SCROW nRow )
return &sc::numeric_block::at(*it->data, aPos.second);
}
-OUString ScColumn::GetInputString( const ScRefCellValue& aCell, SCROW nRow ) const
+OUString ScColumn::GetInputString( const ScRefCellValue& aCell, SCROW nRow, const svl::SharedString** pShared ) const
{
sal_uLong nFormat = GetNumberFormat(GetDoc().GetNonThreadedContext(), nRow);
- return ScCellFormat::GetInputString(aCell, nFormat, *(GetDoc().GetFormatTable()), GetDoc());
+ return ScCellFormat::GetInputString(aCell, nFormat, *(GetDoc().GetFormatTable()), GetDoc(), pShared);
}
double ScColumn::GetValue( SCROW nRow ) const
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 71665e4d6ad6..a16c82bf33ff 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -3561,10 +3561,10 @@ void ScDocument::DiscardFormulaGroupContext()
mpFormulaGroupCxt.reset();
}
-OUString ScDocument::GetInputString( SCCOL nCol, SCROW nRow, SCTAB nTab ) const
+OUString ScDocument::GetInputString( SCCOL nCol, SCROW nRow, SCTAB nTab, const svl::SharedString** pShared ) const
{
if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
- return maTabs[nTab]->GetInputString( nCol, nRow );
+ return maTabs[nTab]->GetInputString( nCol, nRow, pShared );
else
return OUString();
}
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 70fb4e798555..b234825546a1 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1756,10 +1756,10 @@ double* ScTable::GetValueCell( SCCOL nCol, SCROW nRow )
return CreateColumnIfNotExists(nCol).GetValueCell(nRow);
}
-OUString ScTable::GetInputString( SCCOL nCol, SCROW nRow ) const
+OUString ScTable::GetInputString( SCCOL nCol, SCROW nRow, const svl::SharedString** pShared ) const
{
if (ValidColRow(nCol, nRow) && nCol < GetAllocatedColumnsCount())
- return aCol[nCol].GetInputString( nRow );
+ return aCol[nCol].GetInputString( nRow, pShared );
else
return OUString();
}
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index db4e9c25ec24..9c7417278658 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -2607,13 +2607,20 @@ public:
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();
- OUString aStr = ScCellFormat::GetInputString(rCell, nFormat, *pFormatter, mrDoc, rEntry.bDoQuery);
+ 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);
}
}
else
{
- OUString aStr = mrTab.GetInputString(static_cast<SCCOL>(rEntry.nField), nRow);
+ const svl::SharedString* sharedString = nullptr;
+ OUString aStr = mrTab.GetInputString(static_cast<SCCOL>(rEntry.nField), nRow, &sharedString);
+ if( sharedString != nullptr )
+ return compareByStringComparator(rEntry, rItem, sharedString, nullptr);
return compareByStringComparator(rEntry, rItem, nullptr, &aStr);
}
}
diff --git a/sc/source/core/tool/cellform.cxx b/sc/source/core/tool/cellform.cxx
index dd52379bbc29..699f7d88cecb 100644
--- a/sc/source/core/tool/cellform.cxx
+++ b/sc/source/core/tool/cellform.cxx
@@ -128,7 +128,8 @@ OUString ScCellFormat::GetString(
}
OUString ScCellFormat::GetInputString(
- const ScRefCellValue& rCell, sal_uInt32 nFormat, SvNumberFormatter& rFormatter, const ScDocument& rDoc, bool bFiltering )
+ const ScRefCellValue& rCell, sal_uInt32 nFormat, SvNumberFormatter& rFormatter, const ScDocument& rDoc,
+ const svl::SharedString** pShared, bool bFiltering )
{
switch (rCell.meType)
{
@@ -151,11 +152,23 @@ OUString ScCellFormat::GetInputString(
else if (pFC->IsValue())
rFormatter.GetInputLineString(pFC->GetValue(), nFormat, str, bFiltering);
else
- str = pFC->GetString().getString();
+ {
+ const svl::SharedString& shared = pFC->GetString();
+ // Allow callers to optimize by avoiding converting later back to OUString.
+ // To avoid refcounting that won't be needed, do not even return the OUString.
+ if( pShared != nullptr )
+ *pShared = &shared;
+ else
+ str = shared.getString();
+ }
const FormulaError nErrCode = pFC->GetErrCode();
if (nErrCode != FormulaError::NONE)
+ {
str.clear();
+ if( pShared != nullptr )
+ *pShared = nullptr;
+ }
return str;
}