[Libreoffice-commits] .: sw/inc sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Nov 6 06:46:37 PST 2012


 sw/inc/bparr.hxx                |    7 ++++---
 sw/source/core/bastyp/bparr.cxx |   22 ++++++++--------------
 2 files changed, 12 insertions(+), 17 deletions(-)

New commits:
commit 53a227a707a52f1109f7e69022558afd2486659a
Author: Matteo Casalin <matteo.casalin at gmx.com>
Date:   Fri Nov 2 10:20:36 2012 +0100

    Don't play dirty tricks for const objects
    
    Change-Id: I92c2362b71cf3614b091c893c0fdb3248edb3ddd
    Reviewed-on: https://gerrit.libreoffice.org/973
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/inc/bparr.hxx b/sw/inc/bparr.hxx
index 2a644d3..7ce0880 100644
--- a/sw/inc/bparr.hxx
+++ b/sw/inc/bparr.hxx
@@ -75,13 +75,14 @@ struct BlockInfo {                  // block info:
 
 class SW_DLLPUBLIC BigPtrArray
 {
-    BlockInfo** ppInf;              // block info
+    BlockInfo**     ppInf;              // block info
     sal_uLong       nSize;              ///< number of elements
     sal_uInt16      nMaxBlock;          ///< current max. number of blocks
     sal_uInt16      nBlock;             ///< number of blocks
-    sal_uInt16      nCur;               ///< last block
+    mutable
+        sal_uInt16  nCur;               ///< last used block
 
-    sal_uInt16      Index2Block( sal_uLong ) const; ///< block search
+    sal_uInt16  Index2Block( sal_uLong ) const; ///< block search
     BlockInfo*  InsBlock( sal_uInt16 );         ///< insert block
     void        BlockDel( sal_uInt16 );         ///< some blocks were deleted
     void        UpdIndex( sal_uInt16 );         ///< recalculate indices
diff --git a/sw/source/core/bastyp/bparr.cxx b/sw/source/core/bastyp/bparr.cxx
index 72d066e..49d196d 100644
--- a/sw/source/core/bastyp/bparr.cxx
+++ b/sw/source/core/bastyp/bparr.cxx
@@ -128,11 +128,8 @@ void BigPtrArray::ForEach( sal_uLong nStart, sal_uLong nEnd,
 ElementPtr BigPtrArray::operator[]( sal_uLong idx ) const
 {
     assert(idx < nSize); // operator[]: Index out of bounds
-    // because this function is not <const>:
-    BigPtrArray* pThis = (BigPtrArray*) this;
-    sal_uInt16 cur = Index2Block( idx );
-    BlockInfo* p = ppInf[ cur ];
-    pThis->nCur = cur;
+    nCur = Index2Block( idx );
+    BlockInfo* p = ppInf[ nCur ];
     return p->pData[ idx - p->nStart ];
 }
 
@@ -337,8 +334,8 @@ void BigPtrArray::Insert( const ElementPtr& rElem, sal_uLong pos )
             ++( *--pTo = *--pFrom )->nOffset;
     }
     // insert element and update indices
-    ((ElementPtr&)rElem)->nOffset = sal_uInt16(pos);
-    ((ElementPtr&)rElem)->pBlock = p;
+    rElem->nOffset = sal_uInt16(pos);
+    rElem->pBlock = p;
     p->pData[ pos ] = rElem;
     p->nEnd++;
     p->nElem++;
@@ -437,13 +434,10 @@ void BigPtrArray::Remove( sal_uLong pos, sal_uLong n )
 void BigPtrArray::Replace( sal_uLong idx, const ElementPtr& rElem)
 {
     assert(idx < nSize); // Index out of bounds
-    // because this function ist not <const>:
-    BigPtrArray* pThis = (BigPtrArray*) this;
-    sal_uInt16 cur = Index2Block( idx );
-    BlockInfo* p = ppInf[ cur ];
-    pThis->nCur = cur;
-    ((ElementPtr&)rElem)->nOffset = sal_uInt16(idx - p->nStart);
-    ((ElementPtr&)rElem)->pBlock = p;
+    nCur = Index2Block( idx );
+    BlockInfo* p = ppInf[ nCur ];
+    rElem->nOffset = sal_uInt16(idx - p->nStart);
+    rElem->pBlock = p;
     p->pData[ idx - p->nStart ] = rElem;
 }
 


More information about the Libreoffice-commits mailing list