Kaydet (Commit) 41afb3ec authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Delete cell segments using reverse iterator (as TODO comment said).

This makes it much simpler, and less error-prone.

Change-Id: I21dbe0d2bb4a71fc2ac738a5ffb03e4d959d91a5
üst feb5b164
...@@ -165,12 +165,12 @@ void ScColumn::Delete( SCROW nRow ) ...@@ -165,12 +165,12 @@ void ScColumn::Delete( SCROW nRow )
{ {
pNoteCell->Delete(); pNoteCell->Delete();
maItems.erase( maItems.begin() + nIndex); maItems.erase( maItems.begin() + nIndex);
maTextWidths.set_empty(nRow, nRow);
// Should we free memory here (delta)? It'll be slower! // Should we free memory here (delta)? It'll be slower!
} }
pCell->EndListeningTo( pDocument ); pCell->EndListeningTo( pDocument );
pCell->Delete(); pCell->Delete();
maTextWidths.set_empty(nRow, nRow);
CellStorageModified(); CellStorageModified();
} }
} }
...@@ -360,9 +360,6 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe ...@@ -360,9 +360,6 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe
ScHint aHint( SC_HINT_DYING, ScAddress( nCol, 0, nTab ), 0 ); ScHint aHint( SC_HINT_DYING, ScAddress( nCol, 0, nTab ), 0 );
SCROW nStartRow = maItems[nStartIndex].nRow;
SCROW nEndRow = maItems[nEndIndex].nRow;
// cache all formula cells, they will be deleted at end of this function // cache all formula cells, they will be deleted at end of this function
typedef ::std::vector< ScFormulaCell* > FormulaCellVector; typedef ::std::vector< ScFormulaCell* > FormulaCellVector;
FormulaCellVector aDelCells; FormulaCellVector aDelCells;
...@@ -471,50 +468,40 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe ...@@ -471,50 +468,40 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe
if (nFirst <= nEndIndex) if (nFirst <= nEndIndex)
aRemovedSegments.insert_back(nFirst, nEndIndex + 1, true); aRemovedSegments.insert_back(nFirst, nEndIndex + 1, true);
// Remove segments from the column array, containing pDummyCell and formula {
// cell pointers to be deleted. // Remove segments from the column array, containing pDummyCell and
{ // own scope for variables // formula cell pointers to be deleted.
RemovedSegments_t::const_iterator aIt(aRemovedSegments.begin());
RemovedSegments_t::const_iterator aEnd(aRemovedSegments.end()); RemovedSegments_t::const_reverse_iterator it = aRemovedSegments.rbegin();
// The indexes in aRemovedSegments denote cell positions in the RemovedSegments_t::const_reverse_iterator itEnd = aRemovedSegments.rend();
// original array. But as we are shifting it from the left, we have
// to compensate for already performed shifts for latter segments. std::vector<ColEntry>::iterator itErase, itEraseEnd;
// TODO: use reverse iterators instead SCSIZE nEndSegment = it->first; // should equal maItems.size(). Non-inclusive.
SCSIZE nShift(0); // Skip the first node.
SCSIZE nStartSegment(nStartIndex); for (++it; it != itEnd; ++it)
bool bRemoved = false;
for (;aIt != aEnd; ++aIt)
{ {
if (aIt->second) if (!it->second)
{ {
// this segment removed // Don't remove this segment.
if (!bRemoved) nEndSegment = it->first;
nStartSegment = aIt->first;
// The first of removes in a row sets start (they should be
// alternating removed/notremoved anyway).
bRemoved = true;
continue; continue;
} }
if (bRemoved) // Remove this segment.
{ SCSIZE nStartSegment = it->first;
// this segment not removed, but previous segment(s) removed, move tail. SCROW nStartRow = maItems[nStartSegment].nRow;
SCSIZE const nEndSegment(aIt->first); SCROW nEndRow = maItems[nEndSegment-1].nRow;
memmove(
&maItems[nStartSegment - nShift], itErase = maItems.begin();
&maItems[nEndSegment - nShift], std::advance(itErase, nStartSegment);
(maItems.size() - nEndSegment) * sizeof(ColEntry)); itEraseEnd = maItems.begin();
nShift += nEndSegment - nStartSegment; std::advance(itEraseEnd, nEndSegment);
bRemoved = false; maItems.erase(itErase, itEraseEnd);
}
maTextWidths.set_empty(nStartRow, nEndRow);
nEndSegment = nStartSegment;
} }
// The last removed segment up to aItems.size() is discarded, there's
// nothing following to be moved.
if (bRemoved)
nShift += maItems.size() - nStartSegment;
maItems.erase(maItems.end() - nShift, maItems.end());
maTextWidths.set_empty(nStartRow, nEndRow);
CellStorageModified();
} }
// *** delete all formula cells *** // *** delete all formula cells ***
...@@ -1666,8 +1653,8 @@ void ScColumn::RemoveProtected( SCROW nStartRow, SCROW nEndRow ) ...@@ -1666,8 +1653,8 @@ void ScColumn::RemoveProtected( SCROW nStartRow, SCROW nEndRow )
} }
delete pFormula; delete pFormula;
CellStorageModified();
SetTextWidth(maItems[nIndex].nRow, TEXTWIDTH_DIRTY); SetTextWidth(maItems[nIndex].nRow, TEXTWIDTH_DIRTY);
CellStorageModified();
} }
++nIndex; ++nIndex;
} }
......
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