summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2013-10-19 21:35:56 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2013-10-20 13:44:42 -0400
commit81a555edbcea7493c6981dda452bf7d20e06fc02 (patch)
tree27f73b1ff72368aa992e678b4820e3456b6d8754
parent73353186d58ae187f3f1ce4f206795424fb3336c (diff)
Store SharedString in Compare::Cell.
This has a slight overhead for purely numeric comparisons. Change-Id: I243d5c81499177b3ae93b39a1af7c2f3b954bd39
-rw-r--r--sc/inc/compare.hxx7
-rw-r--r--sc/source/core/tool/compare.cxx52
-rw-r--r--sc/source/core/tool/interpr1.cxx18
-rw-r--r--sc/source/core/tool/scmatrix.cxx4
4 files changed, 38 insertions, 43 deletions
diff --git a/sc/inc/compare.hxx b/sc/inc/compare.hxx
index 3189bc81d05a..d188d540b896 100644
--- a/sc/inc/compare.hxx
+++ b/sc/inc/compare.hxx
@@ -22,7 +22,7 @@
#include "queryentry.hxx"
-#include "rtl/ustring.hxx"
+#include "svl/sharedstring.hxx"
class ScDocument;
@@ -33,12 +33,11 @@ struct Compare
struct Cell
{
double mfValue;
- OUString* mpStr;
+ svl::SharedString maStr;
bool mbValue;
bool mbEmpty;
Cell();
- Cell( OUString* p );
};
Cell maCells[2];
@@ -46,7 +45,7 @@ struct Compare
ScQueryOp meOp;
bool mbIgnoreCase;
- Compare( OUString* p1, OUString* p2 );
+ Compare();
};
struct CompareOptions
diff --git a/sc/source/core/tool/compare.cxx b/sc/source/core/tool/compare.cxx
index 5782a6b965de..6c603710ebe3 100644
--- a/sc/source/core/tool/compare.cxx
+++ b/sc/source/core/tool/compare.cxx
@@ -27,17 +27,10 @@
namespace sc {
Compare::Cell::Cell() :
- mfValue(0.0), mpStr(NULL), mbValue(false), mbEmpty(false) {}
+ mfValue(0.0), mbValue(false), mbEmpty(false) {}
-Compare::Cell::Cell( OUString* p ) :
- mfValue(0.0), mpStr(p), mbValue(false), mbEmpty(false) {}
-
-Compare::Compare( OUString* p1, OUString* p2 ) :
- meOp(SC_EQUAL), mbIgnoreCase(true)
-{
- maCells[0] = Cell(p1);
- maCells[1] = Cell(p2);
-}
+Compare::Compare() :
+ meOp(SC_EQUAL), mbIgnoreCase(true) {}
CompareOptions::CompareOptions( ScDocument* pDoc, const ScQueryEntry& rEntry, bool bReg ) :
aQueryEntry(rEntry),
@@ -82,7 +75,7 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions )
}
else
{
- if (!rCell2.mpStr->isEmpty())
+ if (!rCell2.maStr.isEmpty())
fRes = -1; // empty cell < "..."
// else: empty cell == ""
}
@@ -102,7 +95,7 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions )
}
else
{
- if (!rCell1.mpStr->isEmpty())
+ if (!rCell1.maStr.isEmpty())
fRes = 1; // "..." > empty cell
// else: "" == empty cell
}
@@ -139,15 +132,15 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions )
// is/must be identical to *rEntry.pStr, which is essential for
// regex to work through GetSearchTextPtr().
ScQueryEntry& rEntry = pOptions->aQueryEntry;
- OSL_ENSURE(rEntry.GetQueryItem().maString.getString().equals(*rCell2.mpStr), "ScInterpreter::CompareFunc: broken options");
+ OSL_ENSURE(rEntry.GetQueryItem().maString == rCell2.maStr, "ScInterpreter::CompareFunc: broken options");
if (pOptions->bRegEx)
{
sal_Int32 nStart = 0;
- sal_Int32 nStop = rCell1.mpStr->getLength();
+ sal_Int32 nStop = rCell1.maStr.getLength();
bool bMatch = rEntry.GetSearchTextPtr(
!pOptions->bIgnoreCase)->SearchForward(
- *rCell1.mpStr, &nStart, &nStop);
- if (bMatch && pOptions->bMatchWholeCell && (nStart != 0 || nStop != rCell1.mpStr->getLength()))
+ rCell1.maStr.getString(), &nStart, &nStop);
+ if (bMatch && pOptions->bMatchWholeCell && (nStart != 0 || nStop != rCell1.maStr.getLength()))
bMatch = false; // RegEx must match entire string.
fRes = (bMatch ? 0 : 1);
}
@@ -156,34 +149,39 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions )
::utl::TransliterationWrapper* pTransliteration =
(pOptions->bIgnoreCase ? ScGlobal::GetpTransliteration() :
ScGlobal::GetCaseTransliteration());
- bool bMatch;
+ bool bMatch = false;
if (pOptions->bMatchWholeCell)
- bMatch = pTransliteration->isEqual(*rCell1.mpStr, *rCell2.mpStr);
+ {
+ if (pOptions->bIgnoreCase)
+ bMatch = rCell1.maStr.getDataIgnoreCase() == rCell2.maStr.getDataIgnoreCase();
+ else
+ bMatch = rCell1.maStr.getData() == rCell2.maStr.getData();
+ }
else
{
OUString aCell( pTransliteration->transliterate(
- *rCell1.mpStr, ScGlobal::eLnge, 0,
- rCell1.mpStr->getLength(), NULL));
+ rCell1.maStr.getString(), ScGlobal::eLnge, 0,
+ rCell1.maStr.getLength(), NULL));
OUString aQuer( pTransliteration->transliterate(
- *rCell2.mpStr, ScGlobal::eLnge, 0,
- rCell2.mpStr->getLength(), NULL));
+ rCell2.maStr.getString(), ScGlobal::eLnge, 0,
+ rCell2.maStr.getLength(), NULL));
bMatch = (aCell.indexOf( aQuer ) != -1);
}
fRes = (bMatch ? 0 : 1);
}
else if (pOptions->bIgnoreCase)
fRes = (double) ScGlobal::GetCollator()->compareString(
- *rCell1.mpStr, *rCell2.mpStr);
+ rCell1.maStr.getString(), rCell2.maStr.getString());
else
fRes = (double) ScGlobal::GetCaseCollator()->compareString(
- *rCell1.mpStr, *rCell2.mpStr);
+ rCell1.maStr.getString(), rCell2.maStr.getString());
}
else if (rComp.mbIgnoreCase)
fRes = (double) ScGlobal::GetCollator()->compareString(
- *rCell1.mpStr, *rCell2.mpStr);
+ rCell1.maStr.getString(), rCell2.maStr.getString());
else
fRes = (double) ScGlobal::GetCaseCollator()->compareString(
- *rCell1.mpStr, *rCell2.mpStr);
+ rCell1.maStr.getString(), rCell2.maStr.getString());
}
if (nStringQuery && pOptions)
@@ -199,7 +197,7 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions )
// As in ScTable::ValidQuery() match a numeric string for a
// number query that originated from a string, e.g. in SUMIF
// and COUNTIF. Transliteration is not needed here.
- bool bEqual = (*rComp.maCells[nStringQuery-1].mpStr) == rItem.maString.getString();
+ bool bEqual = rComp.maCells[nStringQuery-1].maStr == rItem.maString;
// match => fRes=0, else fRes=1
fRes = (rEntry.eOp == SC_NOT_EQUAL) ? bEqual : !bEqual;
}
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 0de212f23fd9..a598da27c25b 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -791,8 +791,7 @@ bool ScInterpreter::JumpMatrix( short nStackLevel )
double ScInterpreter::Compare()
{
- OUString aVal1, aVal2;
- sc::Compare aComp( &aVal1, &aVal2 );
+ sc::Compare aComp;
aComp.mbIgnoreCase = pDok->GetDocOptions().IsIgnoreCase();
for( short i = 1; i >= 0; i-- )
{
@@ -810,7 +809,7 @@ double ScInterpreter::Compare()
rCell.mbValue = true;
break;
case svString:
- *rCell.mpStr = GetString().getString();
+ rCell.maStr = GetString();
rCell.mbValue = false;
break;
case svDoubleRef :
@@ -827,7 +826,7 @@ double ScInterpreter::Compare()
{
svl::SharedString aStr;
GetCellString(aStr, aCell);
- *rCell.mpStr = aStr.getString();
+ rCell.maStr = aStr;
rCell.mbValue = false;
}
else
@@ -857,7 +856,7 @@ double ScInterpreter::Compare()
rCell.mbEmpty = true;
else if (pMat->IsString(0, 0))
{
- *rCell.mpStr = pMat->GetString(0, 0).getString();
+ rCell.maStr = pMat->GetString(0, 0);
rCell.mbValue = false;
}
else
@@ -883,8 +882,7 @@ double ScInterpreter::Compare()
sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pOptions )
{
- OUString aVal1, aVal2;
- sc::Compare aComp( &aVal1, &aVal2 );
+ sc::Compare aComp;
aComp.meOp = eOp;
aComp.mbIgnoreCase = pDok->GetDocOptions().IsIgnoreCase();
sc::RangeMatrix aMat[2];
@@ -905,7 +903,7 @@ sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pO
rCell.mbValue = true;
break;
case svString:
- *rCell.mpStr = GetString().getString();
+ rCell.maStr = GetString();
rCell.mbValue = false;
break;
case svSingleRef:
@@ -919,7 +917,7 @@ sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pO
{
svl::SharedString aStr;
GetCellString(aStr, aCell);
- *rCell.mpStr = aStr.getString();
+ rCell.maStr = aStr;
rCell.mbValue = false;
}
else
@@ -978,7 +976,7 @@ sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pO
if (aMat[i].mpMat->IsString(j, k))
{
rCell.mbValue = false;
- *rCell.mpStr = aMat[i].mpMat->GetString(j, k).getString();
+ rCell.maStr = aMat[i].mpMat->GetString(j, k);
rCell.mbEmpty = aMat[i].mpMat->IsEmpty(j, k);
}
else
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 3f17535f7e56..18a1dfea12bb 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -1309,7 +1309,7 @@ public:
const svl::SharedString& rStr = *it;
rCell.mbValue = false;
rCell.mbEmpty = false;
- *rCell.mpStr = rStr.getString();
+ rCell.maStr = rStr;
compare();
}
}
@@ -1318,7 +1318,7 @@ public:
{
rCell.mbValue = false;
rCell.mbEmpty = true;
- *rCell.mpStr = svl::SharedString::getEmptyString().getString();
+ rCell.maStr = svl::SharedString::getEmptyString();
for (size_t i = 0; i < node.size; ++i)
compare();
}