diff options
author | Eike Rathke [er] <eike.rathke@oracle.com> | 2010-08-19 17:12:37 +0200 |
---|---|---|
committer | Eike Rathke [er] <eike.rathke@oracle.com> | 2010-08-19 17:12:37 +0200 |
commit | e050b9bc7c26f58d9fcd4c261909249e0522f9df (patch) | |
tree | b1ea133ada1a284c3bcd3ad808a8783404ed1a96 /sc | |
parent | 20cd7f058892c76c9d794c6ff0a776ced306b34d (diff) |
calc58: #i113879# add ScMatrix::CloneIfConst() and regard only temporary matrices created by the interpreter as mutable
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/scmatrix.hxx | 11 | ||||
-rw-r--r-- | sc/source/core/tool/interpr4.cxx | 7 | ||||
-rw-r--r-- | sc/source/core/tool/interpr5.cxx | 19 | ||||
-rw-r--r-- | sc/source/core/tool/scmatrix.cxx | 5 |
4 files changed, 33 insertions, 9 deletions
diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx index 9857d675b7ab..b788672aa715 100644 --- a/sc/inc/scmatrix.hxx +++ b/sc/inc/scmatrix.hxx @@ -99,6 +99,7 @@ class SC_DLLPUBLIC ScMatrix mutable ULONG nRefCnt; // reference count SCSIZE nColCount; SCSIZE nRowCount; + bool mbCloneIfConst; // Whether the matrix is cloned with a CloneIfConst() call. void ResetIsString(); void DeleteIsString(); @@ -171,11 +172,19 @@ public: /** If nC*nR results in more than GetElementsMax() entries, a 1x1 matrix is created instead and a double error value (errStackOverflow) is set. Compare nC and nR with a GetDimensions() call to check. */ - ScMatrix( SCSIZE nC, SCSIZE nR) : nRefCnt(0) { CreateMatrix( nC, nR); } + ScMatrix( SCSIZE nC, SCSIZE nR) : nRefCnt(0), mbCloneIfConst(true) { CreateMatrix( nC, nR); } /** Clone the matrix. */ ScMatrix* Clone() const; + /** Clone the matrix if mbCloneIfConst (immutable) is set, otherwise + return _this_ matrix, to be assigned to a ScMatrixRef. */ + ScMatrix* CloneIfConst(); + + /** Set the matrix to (im)mutable for CloneIfConst(), only the interpreter + should do this and know the consequences. */ + inline void SetImmutable( bool bVal ) { mbCloneIfConst = bVal; } + /** * Resize the matrix to specified new dimension. Note that this operation * clears all stored values. diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index dccb2355b3d5..47cde7186067 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -3970,5 +3970,10 @@ StackVar ScInterpreter::Interpret() while( maxsp-- ) (*p++)->DecRef(); - return xResult->GetType(); + StackVar eType = xResult->GetType(); + if (eType == svMatrix) + // Results are immutable in case they would be reused as input for new + // interpreters. + static_cast<ScToken*>(xResult.operator->())->GetMatrix()->SetImmutable( true); + return eType; } diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx index ba4322a3281a..73794cf15b2d 100644 --- a/sc/source/core/tool/interpr5.cxx +++ b/sc/source/core/tool/interpr5.cxx @@ -310,6 +310,9 @@ ScMatrixRef ScInterpreter::GetNewMat(SCSIZE nC, SCSIZE nR) RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::GetNewMat" ); ScMatrix* pMat = new ScMatrix( nC, nR); pMat->SetErrorInterpreter( this); + // A temporary matrix is mutable and ScMatrix::CloneIfConst() returns the + // very matrix. + pMat->SetImmutable( false); SCSIZE nCols, nRows; pMat->GetDimensions( nCols, nRows); if ( nCols != nC || nRows != nR ) @@ -2069,23 +2072,25 @@ bool ScInterpreter::CheckMatrix(BOOL _bLOG,BOOL _bTrendGrowth,BYTE& nCase,SCSIZE { PushIllegalArgument(); return false; - } // if (!pMatY->IsValue(i)) - } // for ( SCSIZE i = 0; i < nCountY; i++ ) + } + } + if ( _bLOG ) { + ScMatrixRef pNewY = pMatY->CloneIfConst(); for (SCSIZE nElem = 0; nElem < nCountY; nElem++) { - const double fVal = pMatY->GetDouble(nElem); + const double fVal = pNewY->GetDouble(nElem); if (fVal <= 0.0) { PushIllegalArgument(); return false; } else - pMatY->PutDouble(log(fVal), nElem); - } // for (nElem = 0; nElem < nCountY; nElem++) - } // if ( _bRKP ) - + pNewY->PutDouble(log(fVal), nElem); + } + pMatY = pNewY; + } if (pMatX) { diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx index fbb859b64ebf..2ecc20f53405 100644 --- a/sc/source/core/tool/scmatrix.cxx +++ b/sc/source/core/tool/scmatrix.cxx @@ -81,6 +81,11 @@ ScMatrix* ScMatrix::Clone() const return pScMat; } +ScMatrix* ScMatrix::CloneIfConst() +{ + return (mbCloneIfConst || IsEternalRef()) ? Clone() : this; +} + void ScMatrix::Resize( SCSIZE nC, SCSIZE nR) { Clear(); |