Kaydet (Commit) 198a7229 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Move GetHash() from FormulaTokenArray to ScTokenArray.

To allow access to reference tokens.

Change-Id: I3e2d2653722005c04b6d26e1a4ddfce0a459ef37
üst 2b2c20e1
...@@ -94,7 +94,6 @@ public: ...@@ -94,7 +94,6 @@ public:
virtual ~FormulaTokenArray(); virtual ~FormulaTokenArray();
FormulaTokenArray* Clone() const; /// True copy! FormulaTokenArray* Clone() const; /// True copy!
size_t GetHash() const;
void Clear(); void Clear();
void DelRPN(); void DelRPN();
FormulaToken* First() { nIndex = 0; return Next(); } FormulaToken* First() { nIndex = 0; return Next(); }
......
...@@ -685,58 +685,6 @@ FormulaTokenArray* FormulaTokenArray::Clone() const ...@@ -685,58 +685,6 @@ FormulaTokenArray* FormulaTokenArray::Clone() const
return p; return p;
} }
size_t FormulaTokenArray::GetHash() const
{
static OUStringHash aHasher;
size_t nHash = 1;
OpCode eOp;
StackVar eType;
const FormulaToken* p;
sal_uInt16 n = std::min<sal_uInt16>(nLen, 20);
for (sal_uInt16 i = 0; i < n; ++i)
{
p = pCode[i];
eOp = p->GetOpCode();
if (eOp == ocPush)
{
// This is stack variable. Do additional differentiation.
eType = p->GetType();
switch (eType)
{
case svByte:
{
// Constant value.
sal_uInt8 nVal = p->GetByte();
nHash += (static_cast<size_t>(nVal) << i);
continue;
}
case svDouble:
{
// Constant value.
double fVal = p->GetDouble();
nHash += (static_cast<size_t>(fVal) << i);
continue;
}
case svString:
{
// Constant string.
const String& rStr = p->GetString();
nHash += (aHasher(rStr) << i);
continue;
}
default:
// TODO: Decide later if we should generate hash from references as well.
;
}
}
// Use the opcode value in all the other cases.
nHash += (static_cast<size_t>(eOp) << i);
}
return nHash;
}
void FormulaTokenArray::Clear() void FormulaTokenArray::Clear()
{ {
if( nRPN ) DelRPN(); if( nRPN ) DelRPN();
......
...@@ -42,6 +42,8 @@ public: ...@@ -42,6 +42,8 @@ public:
virtual ~ScTokenArray(); virtual ~ScTokenArray();
ScTokenArray* Clone() const; /// True copy! ScTokenArray* Clone() const; /// True copy!
size_t GetHash() const;
/// Exactly and only one range (valid or deleted) /// Exactly and only one range (valid or deleted)
bool IsReference( ScRange& rRange ) const; bool IsReference( ScRange& rRange ) const;
/// Exactly and only one valid range (no #REF!s) /// Exactly and only one valid range (no #REF!s)
......
...@@ -1274,6 +1274,58 @@ bool ScTokenArray::ImplGetReference( ScRange& rRange, bool bValidOnly ) const ...@@ -1274,6 +1274,58 @@ bool ScTokenArray::ImplGetReference( ScRange& rRange, bool bValidOnly ) const
return bIs; return bIs;
} }
size_t ScTokenArray::GetHash() const
{
static OUStringHash aHasher;
size_t nHash = 1;
OpCode eOp;
StackVar eType;
const FormulaToken* p;
sal_uInt16 n = std::min<sal_uInt16>(nLen, 20);
for (sal_uInt16 i = 0; i < n; ++i)
{
p = pCode[i];
eOp = p->GetOpCode();
if (eOp == ocPush)
{
// This is stack variable. Do additional differentiation.
eType = p->GetType();
switch (eType)
{
case svByte:
{
// Constant value.
sal_uInt8 nVal = p->GetByte();
nHash += (static_cast<size_t>(nVal) << i);
continue;
}
case svDouble:
{
// Constant value.
double fVal = p->GetDouble();
nHash += (static_cast<size_t>(fVal) << i);
continue;
}
case svString:
{
// Constant string.
const String& rStr = p->GetString();
nHash += (aHasher(rStr) << i);
continue;
}
default:
// TODO: Decide later if we should generate hash from references as well.
;
}
}
// Use the opcode value in all the other cases.
nHash += (static_cast<size_t>(eOp) << i);
}
return nHash;
}
bool ScTokenArray::IsReference( ScRange& rRange ) const bool ScTokenArray::IsReference( ScRange& rRange ) const
{ {
return ImplGetReference( rRange, false ); return ImplGetReference( rRange, false );
......
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