summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerge Krot <Serge.Krot@cib.de>2018-10-09 10:16:18 +0200
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2018-11-28 00:43:01 +0100
commitd4cd919cf46c0b8d842567fe3d89e20420b6c0f0 (patch)
tree4c44e816f98a718222b0e3aac2e8e1c4cae9bd02
parentsc: avoid checking for time formats in case of SvNumFormatType::NUMBER (diff)
downloadcore-d4cd919cf46c0b8d842567fe3d89e20420b6c0f0.tar.gz
core-d4cd919cf46c0b8d842567fe3d89e20420b6c0f0.zip
sc: speed-up: avoid usage of svl::SharedString where it is possible
Change-Id: I55a1a634927cb1d7a04267d02322fcfa41d390d0 Reviewed-on: https://gerrit.libreoffice.org/61572 Tested-by: Jenkins Reviewed-by: Eike Rathke <erack@redhat.com>
-rw-r--r--sc/source/core/data/table3.cxx111
1 files changed, 74 insertions, 37 deletions
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 07c4030382c2..e59475ff3514 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -2473,28 +2473,22 @@ public:
return std::pair<bool,bool>(bOk, bTestEqual);
}
- std::pair<bool,bool> compareByString(
+ std::pair<bool,bool> compareByString(
ScRefCellValue& rCell, SCROW nRow, const ScQueryEntry& rEntry, const ScQueryEntry::Item& rItem,
const ScInterpreterContext* pContext)
{
- bool bOk = false;
- bool bTestEqual = false;
- bool bMatchWholeCell = mbMatchWholeCell;
- svl::SharedString aCellStr;
- const svl::SharedString* pCellSharedStr = &aCellStr;
- if (isPartialTextMatchOp(rEntry))
- // may have to do partial textural comparison.
- bMatchWholeCell = false;
-
if (!rCell.isEmpty())
{
if (rCell.meType == CELLTYPE_FORMULA && rCell.mpFormula->GetErrCode() != FormulaError::NONE)
{
// Error cell is evaluated as string (for now).
- aCellStr = mrStrPool.intern(ScGlobal::GetErrorString(rCell.mpFormula->GetErrCode()));
+ const svl::SharedString aCellStr = mrStrPool.intern(ScGlobal::GetErrorString(rCell.mpFormula->GetErrCode()));
+ return compareByStringComparator(rEntry, rItem, &aCellStr, nullptr);
}
else if (rCell.meType == CELLTYPE_STRING)
- pCellSharedStr = rCell.mpString;
+ {
+ return compareByStringComparator(rEntry, rItem, rCell.mpString, nullptr);
+ }
else
{
sal_uInt32 nFormat = pContext ? mrTab.GetNumberFormat( *pContext, ScAddress(static_cast<SCCOL>(rEntry.nField), nRow, mrTab.GetTab()) ) :
@@ -2502,41 +2496,58 @@ public:
OUString aStr;
SvNumberFormatter* pFormatter = pContext ? pContext->mpFormatter : mrDoc.GetFormatTable();
ScCellFormat::GetInputString(rCell, nFormat, aStr, *pFormatter, &mrDoc);
- aCellStr = mrStrPool.intern(aStr);
+ return compareByStringComparator(rEntry, rItem, nullptr, &aStr);
}
}
else
{
OUString aStr;
mrTab.GetInputString(static_cast<SCCOL>(rEntry.nField), nRow, aStr);
- aCellStr = mrStrPool.intern(aStr);
+ return compareByStringComparator(rEntry, rItem, nullptr, &aStr);
}
+ }
+
+ // 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,
+ const svl::SharedString* pValueSource1, OUString * pValueSource2)
+ {
+ bool bOk = false;
+ bool bTestEqual = false;
+ bool bMatchWholeCell = mbMatchWholeCell;
+ if (isPartialTextMatchOp(rEntry))
+ // may have to do partial textural comparison.
+ bMatchWholeCell = false;
+
+ const bool bRealWildOrRegExp = isRealWildOrRegExp(rEntry);
+ const bool bTestWildOrRegExp = isTestWildOrRegExp(rEntry);
- const svl::SharedString& rCellStr(*pCellSharedStr);
- bool bRealWildOrRegExp = isRealWildOrRegExp(rEntry);
- bool bTestWildOrRegExp = isTestWildOrRegExp(rEntry);
+ // [pValueSource1] or [pValueSource2] but never both of them or none of them
+ assert((pValueSource1 != nullptr) != (pValueSource2 != nullptr));
if ( bRealWildOrRegExp || bTestWildOrRegExp )
{
+ const OUString & rValue = pValueSource1 ? pValueSource1->getString() : *pValueSource2;
+
sal_Int32 nStart = 0;
- sal_Int32 nEnd = rCellStr.getLength();
+ sal_Int32 nEnd = rValue.getLength();
// from 614 on, nEnd is behind the found text
bool bMatch = false;
if ( rEntry.eOp == SC_ENDS_WITH || rEntry.eOp == SC_DOES_NOT_END_WITH )
{
nEnd = 0;
- nStart = rCellStr.getLength();
+ nStart = rValue.getLength();
bMatch = rEntry.GetSearchTextPtr( mrParam.eSearchType, mrParam.bCaseSens, bMatchWholeCell )
- ->SearchBackward(rCellStr.getString(), &nStart, &nEnd);
+ ->SearchBackward(rValue, &nStart, &nEnd);
}
else
{
bMatch = rEntry.GetSearchTextPtr( mrParam.eSearchType, mrParam.bCaseSens, bMatchWholeCell )
- ->SearchForward(rCellStr.getString(), &nStart, &nEnd);
+ ->SearchForward(rValue, &nStart, &nEnd);
}
if ( bMatch && bMatchWholeCell
- && (nStart != 0 || nEnd != rCellStr.getLength()) )
+ && (nStart != 0 || nEnd != rValue.getLength()) )
bMatch = false; // RegExp must match entire cell string
if ( bRealWildOrRegExp )
{
@@ -2557,10 +2568,10 @@ public:
bOk = !( bMatch && (nStart == 0) );
break;
case SC_ENDS_WITH:
- bOk = ( bMatch && (nEnd == rCellStr.getLength()) );
+ bOk = ( bMatch && (nEnd == rValue.getLength()) );
break;
case SC_DOES_NOT_END_WITH:
- bOk = !( bMatch && (nEnd == rCellStr.getLength()) );
+ bOk = !( bMatch && (nEnd == rValue.getLength()) );
break;
default:
{
@@ -2587,11 +2598,32 @@ public:
}
else if ( bMatchWholeCell )
{
- // Fast string equality check by comparing string identifiers.
- if (mrParam.bCaseSens)
- bOk = rCellStr.getData() == rItem.maString.getData();
- else
- bOk = rCellStr.getDataIgnoreCase() == rItem.maString.getDataIgnoreCase();
+ if (pValueSource1)
+ {
+ // Fast string equality check by comparing string identifiers.
+ if (mrParam.bCaseSens)
+ {
+ bOk = pValueSource1->getData() == rItem.maString.getData();
+ }
+ else
+ {
+ bOk = pValueSource1->getDataIgnoreCase() == rItem.maString.getDataIgnoreCase();
+ }
+ }
+ else // if (pValueSource2)
+ {
+ if (mrParam.bCaseSens)
+ {
+ bOk = (*pValueSource2 == rItem.maString.getString());
+ }
+ else
+ {
+ // fallback
+ const svl::SharedString rSource2(mrStrPool.intern(*pValueSource2));
+ // Fast string equality check by comparing string identifiers.
+ bOk = rSource2.getDataIgnoreCase() == rItem.maString.getDataIgnoreCase();
+ }
+ }
if ( rEntry.eOp == SC_NOT_EQUAL )
bOk = !bOk;
@@ -2603,12 +2635,15 @@ public:
if (!mbCaseSensitive)
{ // Common case for vlookup etc.
+ const svl::SharedString rSource(pValueSource1? *pValueSource1 : mrStrPool.intern(*pValueSource2));
+
const rtl_uString *pQuer = rItem.maString.getDataIgnoreCase();
- const rtl_uString *pCellStr = rCellStr.getDataIgnoreCase();
+ const rtl_uString *pCellStr = rSource.getDataIgnoreCase();
+
assert(pQuer != nullptr);
assert(pCellStr != nullptr);
- sal_Int32 nIndex = (rEntry.eOp == SC_ENDS_WITH ||
+ const sal_Int32 nIndex = (rEntry.eOp == SC_ENDS_WITH ||
rEntry.eOp == SC_DOES_NOT_END_WITH) ?
(pCellStr->length - pQuer->length) : 0;
@@ -2631,18 +2666,19 @@ public:
}
else
{
- OUString aQueryStr = rItem.maString.getString();
+ const OUString & rValue = pValueSource1 ? pValueSource1->getString() : *pValueSource2;
+ const OUString aQueryStr = rItem.maString.getString();
const LanguageType nLang = ScGlobal::pSysLocale->GetLanguageTag().getLanguageType();
setupTransliteratorIfNeeded();
- OUString aCell( mpTransliteration->transliterate(
- rCellStr.getString(), nLang, 0, rCellStr.getLength(),
+ const OUString aCell( mpTransliteration->transliterate(
+ rValue, nLang, 0, rValue.getLength(),
nullptr ) );
- OUString aQuer( mpTransliteration->transliterate(
+ const OUString aQuer( mpTransliteration->transliterate(
aQueryStr, nLang, 0, aQueryStr.getLength(),
nullptr ) );
- sal_Int32 nIndex = (rEntry.eOp == SC_ENDS_WITH || rEntry.eOp == SC_DOES_NOT_END_WITH) ?
+ const sal_Int32 nIndex = (rEntry.eOp == SC_ENDS_WITH || rEntry.eOp == SC_DOES_NOT_END_WITH) ?
(aCell.getLength() - aQuer.getLength()) : 0;
nStrPos = ((nIndex < 0) ? -1 : aCell.indexOf( aQuer, nIndex ));
}
@@ -2681,9 +2717,10 @@ public:
}
else
{ // use collator here because data was probably sorted
+ const OUString & rValue = pValueSource1 ? pValueSource1->getString() : *pValueSource2;
setupCollatorIfNeeded();
sal_Int32 nCompare = mpCollator->compareString(
- rCellStr.getString(), rItem.maString.getString());
+ rValue, rItem.maString.getString());
switch (rEntry.eOp)
{
case SC_LESS :