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 @@ ...@@ -22,7 +22,7 @@
#include "queryentry.hxx" #include "queryentry.hxx"
#include "rtl/ustring.hxx" #include "svl/sharedstring.hxx"
class ScDocument; class ScDocument;
...@@ -33,12 +33,11 @@ struct Compare ...@@ -33,12 +33,11 @@ struct Compare
struct Cell struct Cell
{ {
double mfValue; double mfValue;
OUString* mpStr; svl::SharedString maStr;
bool mbValue; bool mbValue;
bool mbEmpty; bool mbEmpty;
Cell(); Cell();
Cell( OUString* p );
}; };
Cell maCells[2]; Cell maCells[2];
...@@ -46,7 +45,7 @@ struct Compare ...@@ -46,7 +45,7 @@ struct Compare
ScQueryOp meOp; ScQueryOp meOp;
bool mbIgnoreCase; bool mbIgnoreCase;
Compare( OUString* p1, OUString* p2 ); Compare();
}; };
struct CompareOptions struct CompareOptions
......
...@@ -27,17 +27,10 @@ ...@@ -27,17 +27,10 @@
namespace sc { namespace sc {
Compare::Cell::Cell() : Compare::Cell::Cell() :
mfValue(0.0), mpStr(NULL), mbValue(false), mbEmpty(false) {} mfValue(0.0), mbValue(false), mbEmpty(false) {}
Compare::Cell::Cell( OUString* p ) : Compare::Compare() :
mfValue(0.0), mpStr(p), mbValue(false), mbEmpty(false) {} meOp(SC_EQUAL), mbIgnoreCase(true) {}
Compare::Compare( OUString* p1, OUString* p2 ) :
meOp(SC_EQUAL), mbIgnoreCase(true)
{
maCells[0] = Cell(p1);
maCells[1] = Cell(p2);
}
CompareOptions::CompareOptions( ScDocument* pDoc, const ScQueryEntry& rEntry, bool bReg ) : CompareOptions::CompareOptions( ScDocument* pDoc, const ScQueryEntry& rEntry, bool bReg ) :
aQueryEntry(rEntry), aQueryEntry(rEntry),
...@@ -82,7 +75,7 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions ) ...@@ -82,7 +75,7 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions )
} }
else else
{ {
if (!rCell2.mpStr->isEmpty()) if (!rCell2.maStr.isEmpty())
fRes = -1; // empty cell < "..." fRes = -1; // empty cell < "..."
// else: empty cell == "" // else: empty cell == ""
} }
...@@ -102,7 +95,7 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions ) ...@@ -102,7 +95,7 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions )
} }
else else
{ {
if (!rCell1.mpStr->isEmpty()) if (!rCell1.maStr.isEmpty())
fRes = 1; // "..." > empty cell fRes = 1; // "..." > empty cell
// else: "" == empty cell // else: "" == empty cell
} }
...@@ -139,15 +132,15 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions ) ...@@ -139,15 +132,15 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions )
// is/must be identical to *rEntry.pStr, which is essential for // is/must be identical to *rEntry.pStr, which is essential for
// regex to work through GetSearchTextPtr(). // regex to work through GetSearchTextPtr().
ScQueryEntry& rEntry = pOptions->aQueryEntry; 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) if (pOptions->bRegEx)
{ {
sal_Int32 nStart = 0; sal_Int32 nStart = 0;
sal_Int32 nStop = rCell1.mpStr->getLength(); sal_Int32 nStop = rCell1.maStr.getLength();
bool bMatch = rEntry.GetSearchTextPtr( bool bMatch = rEntry.GetSearchTextPtr(
!pOptions->bIgnoreCase)->SearchForward( !pOptions->bIgnoreCase)->SearchForward(
*rCell1.mpStr, &nStart, &nStop); rCell1.maStr.getString(), &nStart, &nStop);
if (bMatch && pOptions->bMatchWholeCell && (nStart != 0 || nStop != rCell1.mpStr->getLength())) if (bMatch && pOptions->bMatchWholeCell && (nStart != 0 || nStop != rCell1.maStr.getLength()))
bMatch = false; // RegEx must match entire string. bMatch = false; // RegEx must match entire string.
fRes = (bMatch ? 0 : 1); fRes = (bMatch ? 0 : 1);
} }
...@@ -156,34 +149,39 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions ) ...@@ -156,34 +149,39 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions )
::utl::TransliterationWrapper* pTransliteration = ::utl::TransliterationWrapper* pTransliteration =
(pOptions->bIgnoreCase ? ScGlobal::GetpTransliteration() : (pOptions->bIgnoreCase ? ScGlobal::GetpTransliteration() :
ScGlobal::GetCaseTransliteration()); ScGlobal::GetCaseTransliteration());
bool bMatch; bool bMatch = false;
if (pOptions->bMatchWholeCell) 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 else
{ {
OUString aCell( pTransliteration->transliterate( OUString aCell( pTransliteration->transliterate(
*rCell1.mpStr, ScGlobal::eLnge, 0, rCell1.maStr.getString(), ScGlobal::eLnge, 0,
rCell1.mpStr->getLength(), NULL)); rCell1.maStr.getLength(), NULL));
OUString aQuer( pTransliteration->transliterate( OUString aQuer( pTransliteration->transliterate(
*rCell2.mpStr, ScGlobal::eLnge, 0, rCell2.maStr.getString(), ScGlobal::eLnge, 0,
rCell2.mpStr->getLength(), NULL)); rCell2.maStr.getLength(), NULL));
bMatch = (aCell.indexOf( aQuer ) != -1); bMatch = (aCell.indexOf( aQuer ) != -1);
} }
fRes = (bMatch ? 0 : 1); fRes = (bMatch ? 0 : 1);
} }
else if (pOptions->bIgnoreCase) else if (pOptions->bIgnoreCase)
fRes = (double) ScGlobal::GetCollator()->compareString( fRes = (double) ScGlobal::GetCollator()->compareString(
*rCell1.mpStr, *rCell2.mpStr); rCell1.maStr.getString(), rCell2.maStr.getString());
else else
fRes = (double) ScGlobal::GetCaseCollator()->compareString( fRes = (double) ScGlobal::GetCaseCollator()->compareString(
*rCell1.mpStr, *rCell2.mpStr); rCell1.maStr.getString(), rCell2.maStr.getString());
} }
else if (rComp.mbIgnoreCase) else if (rComp.mbIgnoreCase)
fRes = (double) ScGlobal::GetCollator()->compareString( fRes = (double) ScGlobal::GetCollator()->compareString(
*rCell1.mpStr, *rCell2.mpStr); rCell1.maStr.getString(), rCell2.maStr.getString());
else else
fRes = (double) ScGlobal::GetCaseCollator()->compareString( fRes = (double) ScGlobal::GetCaseCollator()->compareString(
*rCell1.mpStr, *rCell2.mpStr); rCell1.maStr.getString(), rCell2.maStr.getString());
} }
if (nStringQuery && pOptions) if (nStringQuery && pOptions)
...@@ -199,7 +197,7 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions ) ...@@ -199,7 +197,7 @@ double CompareFunc( const Compare& rComp, CompareOptions* pOptions )
// As in ScTable::ValidQuery() match a numeric string for a // As in ScTable::ValidQuery() match a numeric string for a
// number query that originated from a string, e.g. in SUMIF // number query that originated from a string, e.g. in SUMIF
// and COUNTIF. Transliteration is not needed here. // 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 // match => fRes=0, else fRes=1
fRes = (rEntry.eOp == SC_NOT_EQUAL) ? bEqual : !bEqual; fRes = (rEntry.eOp == SC_NOT_EQUAL) ? bEqual : !bEqual;
} }
......
...@@ -791,8 +791,7 @@ bool ScInterpreter::JumpMatrix( short nStackLevel ) ...@@ -791,8 +791,7 @@ bool ScInterpreter::JumpMatrix( short nStackLevel )
double ScInterpreter::Compare() double ScInterpreter::Compare()
{ {
OUString aVal1, aVal2; sc::Compare aComp;
sc::Compare aComp( &aVal1, &aVal2 );
aComp.mbIgnoreCase = pDok->GetDocOptions().IsIgnoreCase(); aComp.mbIgnoreCase = pDok->GetDocOptions().IsIgnoreCase();
for( short i = 1; i >= 0; i-- ) for( short i = 1; i >= 0; i-- )
{ {
...@@ -810,7 +809,7 @@ double ScInterpreter::Compare() ...@@ -810,7 +809,7 @@ double ScInterpreter::Compare()
rCell.mbValue = true; rCell.mbValue = true;
break; break;
case svString: case svString:
*rCell.mpStr = GetString().getString(); rCell.maStr = GetString();
rCell.mbValue = false; rCell.mbValue = false;
break; break;
case svDoubleRef : case svDoubleRef :
...@@ -827,7 +826,7 @@ double ScInterpreter::Compare() ...@@ -827,7 +826,7 @@ double ScInterpreter::Compare()
{ {
svl::SharedString aStr; svl::SharedString aStr;
GetCellString(aStr, aCell); GetCellString(aStr, aCell);
*rCell.mpStr = aStr.getString(); rCell.maStr = aStr;
rCell.mbValue = false; rCell.mbValue = false;
} }
else else
...@@ -857,7 +856,7 @@ double ScInterpreter::Compare() ...@@ -857,7 +856,7 @@ double ScInterpreter::Compare()
rCell.mbEmpty = true; rCell.mbEmpty = true;
else if (pMat->IsString(0, 0)) else if (pMat->IsString(0, 0))
{ {
*rCell.mpStr = pMat->GetString(0, 0).getString(); rCell.maStr = pMat->GetString(0, 0);
rCell.mbValue = false; rCell.mbValue = false;
} }
else else
...@@ -883,8 +882,7 @@ double ScInterpreter::Compare() ...@@ -883,8 +882,7 @@ double ScInterpreter::Compare()
sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pOptions ) sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pOptions )
{ {
OUString aVal1, aVal2; sc::Compare aComp;
sc::Compare aComp( &aVal1, &aVal2 );
aComp.meOp = eOp; aComp.meOp = eOp;
aComp.mbIgnoreCase = pDok->GetDocOptions().IsIgnoreCase(); aComp.mbIgnoreCase = pDok->GetDocOptions().IsIgnoreCase();
sc::RangeMatrix aMat[2]; sc::RangeMatrix aMat[2];
...@@ -905,7 +903,7 @@ sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pO ...@@ -905,7 +903,7 @@ sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pO
rCell.mbValue = true; rCell.mbValue = true;
break; break;
case svString: case svString:
*rCell.mpStr = GetString().getString(); rCell.maStr = GetString();
rCell.mbValue = false; rCell.mbValue = false;
break; break;
case svSingleRef: case svSingleRef:
...@@ -919,7 +917,7 @@ sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pO ...@@ -919,7 +917,7 @@ sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pO
{ {
svl::SharedString aStr; svl::SharedString aStr;
GetCellString(aStr, aCell); GetCellString(aStr, aCell);
*rCell.mpStr = aStr.getString(); rCell.maStr = aStr;
rCell.mbValue = false; rCell.mbValue = false;
} }
else else
...@@ -978,7 +976,7 @@ sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pO ...@@ -978,7 +976,7 @@ sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pO
if (aMat[i].mpMat->IsString(j, k)) if (aMat[i].mpMat->IsString(j, k))
{ {
rCell.mbValue = false; 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); rCell.mbEmpty = aMat[i].mpMat->IsEmpty(j, k);
} }
else else
......
...@@ -1309,7 +1309,7 @@ public: ...@@ -1309,7 +1309,7 @@ public:
const svl::SharedString& rStr = *it; const svl::SharedString& rStr = *it;
rCell.mbValue = false; rCell.mbValue = false;
rCell.mbEmpty = false; rCell.mbEmpty = false;
*rCell.mpStr = rStr.getString(); rCell.maStr = rStr;
compare(); compare();
} }
} }
...@@ -1318,7 +1318,7 @@ public: ...@@ -1318,7 +1318,7 @@ public:
{ {
rCell.mbValue = false; rCell.mbValue = false;
rCell.mbEmpty = true; rCell.mbEmpty = true;
*rCell.mpStr = svl::SharedString::getEmptyString().getString(); rCell.maStr = svl::SharedString::getEmptyString();
for (size_t i = 0; i < node.size; ++i) for (size_t i = 0; i < node.size; ++i)
compare(); 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