[Libreoffice-commits] .: sc/source

Eike Rathke erack at kemper.freedesktop.org
Tue Aug 23 15:01:31 PDT 2011


 sc/source/core/data/column3.cxx |   48 ++++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 19 deletions(-)

New commits:
commit de247b8805d3e60d2181ac6369b07f0a494cd1b6
Author: Eike Rathke <erack at erack.de>
Date:   Tue Aug 23 23:50:08 2011 +0200

    adapt to unused memory correctly
    
    * ScColumn::DeleteRange() still failed in a case when cells of the very
      last part of memory were removed that did not encompass the entire
      range passed and nCount wasn't decremented as a result. Refactored
      that loop over RemovedSegments.

diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 384f98f..8e8037a 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -530,33 +530,43 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe
     {
         RemovedSegments_t::const_iterator aIt(aRemovedSegments.begin());
         RemovedSegments_t::const_iterator aEnd(aRemovedSegments.end());
-        if (aIt != aEnd)
+        // The indexes in aRemovedSegments denote cell positions in the
+        // original array. But as we are shifting it from the left, we have
+        // to compensate for already performed shifts for latter segments.
+        // TODO: use reverse iterators instead
+        SCSIZE nShift(0);
+        SCSIZE nStartSegment(nStartIndex);
+        bool bRemoved = false;
+        while (aIt != aEnd)
         {
-            SCSIZE nStartSegment(aIt->first);
-            bool bMoveSegment(aIt->second);
-            // The indexes in aRemovedSegments denote cell positions in the
-            // original array. But as we are shifting it from the left, we have
-            // to compensate for already performed shifts for latter segments.
-            // TODO: use reverse iterators instead
-            SCSIZE nShift(0);
-            ++aIt;
-            do
-            {
-                SCSIZE const nEndSegment(aIt->first);
-                if (bMoveSegment)
-                {
+            if (aIt->second)
+            { // this segment removed
+                if (!bRemoved)
+                    nStartSegment = aIt->first;
+                    // The first of removes in a row sets start (they should be 
+                    // alternating removed/notremoved anyway).
+                bRemoved = true;
+            }
+            else
+            { // this segment not removed
+                if (bRemoved)
+                { // previous segment(s) removed, move tail
+                    SCSIZE const nEndSegment(aIt->first);
                     memmove(
                             &pItems[nStartSegment - nShift],
                             &pItems[nEndSegment - nShift],
                             (nCount - nEndSegment) * sizeof(ColEntry));
                     nShift += nEndSegment - nStartSegment;
+                    bRemoved = false;
                 }
-                nStartSegment = nEndSegment;
-                bMoveSegment = aIt->second;
-                ++aIt;
-            } while (aIt != aEnd);
-            nCount -= nShift;
+            }
+            ++aIt;
         }
+        // The last removed segment up to nCount is discarded, there's nothing 
+        // following to be moved.
+        if (bRemoved)
+            nShift += nCount - nStartSegment;
+        nCount -= nShift;
     }
 
     // *** delete all formula cells ***


More information about the Libreoffice-commits mailing list