diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-03-18 19:40:08 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-03-19 13:40:24 -0400 |
commit | d65e83b32f7cf8227984b843a783d55c384c373b (patch) | |
tree | 7f0cad0553d8640d4d289e49662f475c4d794dbc /sc | |
parent | 0a0deec6f1e5c3e3100673daa6ef244b2d8ff8bf (diff) |
Generate token array hash exactly once, when the string is tokenized.
And CompileString() is the place to do it, to the best of my knowledge.
Change-Id: I249df5d09aa288eacc2b2c7ad6e5fc947a3c225f
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/tokenarray.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 1 | ||||
-rw-r--r-- | sc/source/core/tool/token.cxx | 21 |
3 files changed, 19 insertions, 6 deletions
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx index 01993e94847e..e3b7d5679272 100644 --- a/sc/inc/tokenarray.hxx +++ b/sc/inc/tokenarray.hxx @@ -35,6 +35,8 @@ class SC_DLLPUBLIC ScTokenArray : public formula::FormulaTokenArray friend class ScCompiler; bool ImplGetReference( ScRange& rRange, bool bValidOnly ) const; + size_t mnHashValue; + public: ScTokenArray(); /// Assignment with references to ScToken entries (not copied!) @@ -42,6 +44,7 @@ public: virtual ~ScTokenArray(); ScTokenArray* Clone() const; /// True copy! + void GenHash(); size_t GetHash() const; /// Exactly and only one range (valid or deleted) diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index b4850ca1cfb4..07f4673486c3 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -3951,6 +3951,7 @@ ScTokenArray* ScCompiler::CompileString( const String& rFormula ) // remember pArr, in case a subsequent CompileTokenArray() is executed. ScTokenArray* pNew = new ScTokenArray( aArr ); + pNew->GenHash(); pArr = pNew; if (!maExternalFiles.empty()) diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index a19f2e3f1b52..b59517756202 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -1294,7 +1294,7 @@ size_t HashSingleRef( const ScSingleRefData& rRef ) } -size_t ScTokenArray::GetHash() const +void ScTokenArray::GenHash() { static OUStringHash aHasher; @@ -1357,7 +1357,13 @@ size_t ScTokenArray::GetHash() const // Use the opcode value in all the other cases. nHash += (static_cast<size_t>(eOp) << i); } - return nHash; + + mnHashValue = nHash; +} + +size_t ScTokenArray::GetHash() const +{ + return mnHashValue; } bool ScTokenArray::IsReference( ScRange& rRange ) const @@ -1372,11 +1378,15 @@ bool ScTokenArray::IsValidReference( ScRange& rRange ) const //////////////////////////////////////////////////////////////////////////// -ScTokenArray::ScTokenArray() +ScTokenArray::ScTokenArray() : + FormulaTokenArray(), + mnHashValue(0) { } -ScTokenArray::ScTokenArray( const ScTokenArray& rArr ) : FormulaTokenArray(rArr) +ScTokenArray::ScTokenArray( const ScTokenArray& rArr ) : + FormulaTokenArray(rArr), + mnHashValue(rArr.mnHashValue) { } @@ -1384,8 +1394,6 @@ ScTokenArray::~ScTokenArray() { } - - ScTokenArray& ScTokenArray::operator=( const ScTokenArray& rArr ) { Clear(); @@ -1402,6 +1410,7 @@ ScTokenArray* ScTokenArray::Clone() const p->nMode = nMode; p->nError = nError; p->bHyperLink = bHyperLink; + p->mnHashValue = mnHashValue; FormulaToken** pp; if( nLen ) { |