diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-07-18 11:29:12 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-07-19 14:05:12 -0400 |
commit | ed5d2c652cd053cd10f54fb028f513f20d6c6086 (patch) | |
tree | ee3a08c8e5da337240bac65d4379962605ba8bb3 /sc | |
parent | 32d9ed46f6075c66e233b3c8f8036beceb60d87c (diff) |
Less indentations via early bailout.
Change-Id: Iae2b91fc732debe9b5c9cdd7c4717e1ef2fac08e
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/tool/interpr5.cxx | 128 |
1 files changed, 66 insertions, 62 deletions
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx index c689729d6862..fb1a49601792 100644 --- a/sc/source/core/tool/interpr5.cxx +++ b/sc/source/core/tool/interpr5.cxx @@ -355,75 +355,79 @@ ScMatrixRef ScInterpreter::CreateMatrixFromDoubleRef( const FormulaToken* pToken SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2 ) { - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::CreateMatrixFromDoubleRef" ); - ScMatrixRef pMat = NULL; - if (nTab1 == nTab2 && !nGlobalError) - { - ScTokenMatrixMap::const_iterator aIter; - if ( static_cast<SCSIZE>(nRow2 - nRow1 + 1) * - static_cast<SCSIZE>(nCol2 - nCol1 + 1) > - ScMatrix::GetElementsMax() ) - SetError(errStackOverflow); - else if (pTokenMatrixMap && ((aIter = pTokenMatrixMap->find( pToken)) - != pTokenMatrixMap->end())) - pMat = static_cast<ScToken*>((*aIter).second.get())->GetMatrix(); - else - { - SCSIZE nMatCols = static_cast<SCSIZE>(nCol2 - nCol1 + 1); - SCSIZE nMatRows = static_cast<SCSIZE>(nRow2 - nRow1 + 1); - pMat = GetNewMat( nMatCols, nMatRows, true); - if (pMat && !nGlobalError) - { - ScCellIterator aCellIter( - pDok, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2); + if (nTab1 != nTab2 || nGlobalError) + { + // Not a 2D matrix. + SetError(errIllegalParameter); + return NULL; + } - for (ScBaseCell* pCell = aCellIter.GetFirst(); pCell; pCell = - aCellIter.GetNext()) - { - SCCOL nThisCol = aCellIter.GetCol(); - SCROW nThisRow = aCellIter.GetRow(); - if (HasCellEmptyData(pCell)) - continue; + SCSIZE nMatCols = static_cast<SCSIZE>(nCol2 - nCol1 + 1); + SCSIZE nMatRows = static_cast<SCSIZE>(nRow2 - nRow1 + 1); - if (HasCellValueData(pCell)) - { - ScAddress aAdr( nThisCol, nThisRow, nTab1); - double fVal = GetCellValue( aAdr, pCell); - if ( nGlobalError ) - { - fVal = CreateDoubleError( nGlobalError); - nGlobalError = 0; - } - pMat->PutDouble( fVal, - static_cast<SCSIZE>(nThisCol-nCol1), - static_cast<SCSIZE>(nThisRow-nRow1)); - continue; - } + if (nMatRows * nMatCols > ScMatrix::GetElementsMax()) + { + SetError(errStackOverflow); + return NULL; + } - String aStr; - GetCellString( aStr, pCell); - if ( nGlobalError ) - { - double fVal = CreateDoubleError( nGlobalError); - nGlobalError = 0; - pMat->PutDouble( fVal, - static_cast<SCSIZE>(nThisCol-nCol1), - static_cast<SCSIZE>(nThisRow-nRow1)); - } - else - pMat->PutString( aStr, - static_cast<SCSIZE>(nThisCol-nCol1), - static_cast<SCSIZE>(nThisRow-nRow1)); - } + ScTokenMatrixMap::const_iterator aIter; + if (pTokenMatrixMap && ((aIter = pTokenMatrixMap->find( pToken)) + != pTokenMatrixMap->end())) + { + return static_cast<ScToken*>((*aIter).second.get())->GetMatrix(); + } + + ScMatrixRef pMat = GetNewMat( nMatCols, nMatRows, true); + if (!pMat || nGlobalError) + return NULL; - if (pTokenMatrixMap) - pTokenMatrixMap->insert( ScTokenMatrixMap::value_type( - pToken, new ScMatrixToken( pMat))); + ScCellIterator aCellIter( + pDok, nCol1, nRow1, nTab1, nCol2, nRow2, nTab2); + + for (ScBaseCell* pCell = aCellIter.GetFirst(); pCell; pCell = + aCellIter.GetNext()) + { + SCCOL nThisCol = aCellIter.GetCol(); + SCROW nThisRow = aCellIter.GetRow(); + if (HasCellEmptyData(pCell)) + continue; + + if (HasCellValueData(pCell)) + { + ScAddress aAdr( nThisCol, nThisRow, nTab1); + double fVal = GetCellValue( aAdr, pCell); + if ( nGlobalError ) + { + fVal = CreateDoubleError( nGlobalError); + nGlobalError = 0; } + pMat->PutDouble( fVal, + static_cast<SCSIZE>(nThisCol-nCol1), + static_cast<SCSIZE>(nThisRow-nRow1)); + continue; + } + + String aStr; + GetCellString( aStr, pCell); + if ( nGlobalError ) + { + double fVal = CreateDoubleError( nGlobalError); + nGlobalError = 0; + pMat->PutDouble( fVal, + static_cast<SCSIZE>(nThisCol-nCol1), + static_cast<SCSIZE>(nThisRow-nRow1)); } + else + pMat->PutString( aStr, + static_cast<SCSIZE>(nThisCol-nCol1), + static_cast<SCSIZE>(nThisRow-nRow1)); } - else // not a 2D matrix - SetError(errIllegalParameter); + + if (pTokenMatrixMap) + pTokenMatrixMap->insert( ScTokenMatrixMap::value_type( + pToken, new ScMatrixToken( pMat))); + return pMat; } |