diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-11-01 17:55:34 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-11-01 20:16:53 -0400 |
commit | 1f422ffb23747cdc16dbeca5d0222d66fbab383c (patch) | |
tree | 1d41236f83bc17f9bd211298f6b2adce57ad2eda | |
parent | 1219bcb0c4f1dd1753c8bb63baf957f878971b70 (diff) |
Prefer early bailout to avoid big fat if block.
Change-Id: I028606c41b1486349f96b62e0ddb071ad46e9e55
-rw-r--r-- | sc/source/core/data/column.cxx | 127 |
1 files changed, 63 insertions, 64 deletions
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index 3636f6009ceb..ffff6574dc5e 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -1472,87 +1472,86 @@ void ScColumn::SwapCol(ScColumn& rCol) } } - void ScColumn::MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol) { pAttrArray->MoveTo(nStartRow, nEndRow, *rCol.pAttrArray); - if ( !maItems.empty() ) + if (maItems.empty()) + // No cells to move. + return; + + ::std::vector<SCROW> aRows; + bool bConsecutive = true; + SCSIZE i; + Search( nStartRow, i); // i points to start row or position thereafter + SCSIZE nStartPos = i; + for ( ; i < maItems.size() && maItems[i].nRow <= nEndRow; ++i) { - ::std::vector<SCROW> aRows; - bool bConsecutive = true; - SCSIZE i; - Search( nStartRow, i); // i points to start row or position thereafter - SCSIZE nStartPos = i; - for ( ; i < maItems.size() && maItems[i].nRow <= nEndRow; ++i) - { - SCROW nRow = maItems[i].nRow; - aRows.push_back( nRow); - rCol.Insert( nRow, maItems[i].pCell); - if (nRow != maItems[i].nRow) - { // Listener inserted - bConsecutive = false; - Search( nRow, i); - } + SCROW nRow = maItems[i].nRow; + aRows.push_back( nRow); + rCol.Insert( nRow, maItems[i].pCell); + if (nRow != maItems[i].nRow) + { // Listener inserted + bConsecutive = false; + Search( nRow, i); } - SCSIZE nStopPos = i; - if (nStartPos < nStopPos) + } + SCSIZE nStopPos = i; + if (nStartPos < nStopPos) + { + // Create list of ranges of cell entry positions + typedef ::std::pair<SCSIZE,SCSIZE> PosPair; + typedef ::std::vector<PosPair> EntryPosPairs; + EntryPosPairs aEntries; + if (bConsecutive) + aEntries.push_back( PosPair(nStartPos, nStopPos)); + else { - // Create list of ranges of cell entry positions - typedef ::std::pair<SCSIZE,SCSIZE> PosPair; - typedef ::std::vector<PosPair> EntryPosPairs; - EntryPosPairs aEntries; - if (bConsecutive) - aEntries.push_back( PosPair(nStartPos, nStopPos)); - else + bool bFirst = true; + nStopPos = 0; + for (::std::vector<SCROW>::const_iterator it( aRows.begin()); + it != aRows.end() && nStopPos < maItems.size(); ++it, + ++nStopPos) { - bool bFirst = true; - nStopPos = 0; - for (::std::vector<SCROW>::const_iterator it( aRows.begin()); - it != aRows.end() && nStopPos < maItems.size(); ++it, - ++nStopPos) + if (!bFirst && *it != maItems[nStopPos].nRow) { - if (!bFirst && *it != maItems[nStopPos].nRow) - { - aEntries.push_back( PosPair(nStartPos, nStopPos)); - bFirst = true; - } - if (bFirst && Search( *it, nStartPos)) - { - bFirst = false; - nStopPos = nStartPos; - } - } - if (!bFirst && nStartPos < nStopPos) aEntries.push_back( PosPair(nStartPos, nStopPos)); - } - // Broadcast changes - ScAddress aAdr( nCol, 0, nTab ); - ScHint aHint( SC_HINT_DYING, aAdr, NULL ); // areas only - ScAddress& rAddress = aHint.GetAddress(); - ScNoteCell* pNoteCell = new ScNoteCell; // Dummy like in DeleteRange - - // must iterate backwards, because indexes of following cells become invalid - for (EntryPosPairs::reverse_iterator it( aEntries.rbegin()); - it != aEntries.rend(); ++it) - { - nStartPos = (*it).first; - nStopPos = (*it).second; - for (i=nStartPos; i<nStopPos; ++i) - maItems[i].pCell = pNoteCell; - for (i=nStartPos; i<nStopPos; ++i) + bFirst = true; + } + if (bFirst && Search( *it, nStartPos)) { - rAddress.SetRow( maItems[i].nRow ); - pDocument->AreaBroadcast( aHint ); + bFirst = false; + nStopPos = nStartPos; } - maItems.erase(maItems.begin() + nStartPos, maItems.begin() + nStopPos - 1); } - pNoteCell->Delete(); + if (!bFirst && nStartPos < nStopPos) + aEntries.push_back( PosPair(nStartPos, nStopPos)); } + // Broadcast changes + ScAddress aAdr( nCol, 0, nTab ); + ScHint aHint( SC_HINT_DYING, aAdr, NULL ); // areas only + ScAddress& rAddress = aHint.GetAddress(); + ScNoteCell* pNoteCell = new ScNoteCell; // Dummy like in DeleteRange + + // must iterate backwards, because indexes of following cells become invalid + for (EntryPosPairs::reverse_iterator it( aEntries.rbegin()); + it != aEntries.rend(); ++it) + { + nStartPos = (*it).first; + nStopPos = (*it).second; + for (i=nStartPos; i<nStopPos; ++i) + maItems[i].pCell = pNoteCell; + for (i=nStartPos; i<nStopPos; ++i) + { + rAddress.SetRow( maItems[i].nRow ); + pDocument->AreaBroadcast( aHint ); + } + maItems.erase(maItems.begin() + nStartPos, maItems.begin() + nStopPos - 1); + } + pNoteCell->Delete(); } } - bool ScColumn::UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, SCsCOL nDx, SCsROW nDy, SCsTAB nDz, ScDocument* pUndoDoc ) |