Kaydet (Commit) 81a555ed authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Store SharedString in Compare::Cell.

This has a slight overhead for purely numeric comparisons.

Change-Id: I243d5c81499177b3ae93b39a1af7c2f3b954bd39
üst 73353186
......@@ -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
......
......@@ -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;
}
......
......@@ -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
......
......@@ -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();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment