Kaydet (Commit) 53a227a7 authored tarafından Matteo Casalin's avatar Matteo Casalin Kaydeden (comit) Caolán McNamara

Don't play dirty tricks for const objects

Change-Id: I92c2362b71cf3614b091c893c0fdb3248edb3ddd
Reviewed-on: https://gerrit.libreoffice.org/973Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst f354ba7a
...@@ -79,7 +79,8 @@ class SW_DLLPUBLIC BigPtrArray ...@@ -79,7 +79,8 @@ class SW_DLLPUBLIC BigPtrArray
sal_uLong nSize; ///< number of elements sal_uLong nSize; ///< number of elements
sal_uInt16 nMaxBlock; ///< current max. number of blocks sal_uInt16 nMaxBlock; ///< current max. number of blocks
sal_uInt16 nBlock; ///< 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 BlockInfo* InsBlock( sal_uInt16 ); ///< insert block
......
...@@ -128,11 +128,8 @@ void BigPtrArray::ForEach( sal_uLong nStart, sal_uLong nEnd, ...@@ -128,11 +128,8 @@ void BigPtrArray::ForEach( sal_uLong nStart, sal_uLong nEnd,
ElementPtr BigPtrArray::operator[]( sal_uLong idx ) const ElementPtr BigPtrArray::operator[]( sal_uLong idx ) const
{ {
assert(idx < nSize); // operator[]: Index out of bounds assert(idx < nSize); // operator[]: Index out of bounds
// because this function is not <const>: nCur = Index2Block( idx );
BigPtrArray* pThis = (BigPtrArray*) this; BlockInfo* p = ppInf[ nCur ];
sal_uInt16 cur = Index2Block( idx );
BlockInfo* p = ppInf[ cur ];
pThis->nCur = cur;
return p->pData[ idx - p->nStart ]; return p->pData[ idx - p->nStart ];
} }
...@@ -337,8 +334,8 @@ void BigPtrArray::Insert( const ElementPtr& rElem, sal_uLong pos ) ...@@ -337,8 +334,8 @@ void BigPtrArray::Insert( const ElementPtr& rElem, sal_uLong pos )
++( *--pTo = *--pFrom )->nOffset; ++( *--pTo = *--pFrom )->nOffset;
} }
// insert element and update indices // insert element and update indices
((ElementPtr&)rElem)->nOffset = sal_uInt16(pos); rElem->nOffset = sal_uInt16(pos);
((ElementPtr&)rElem)->pBlock = p; rElem->pBlock = p;
p->pData[ pos ] = rElem; p->pData[ pos ] = rElem;
p->nEnd++; p->nEnd++;
p->nElem++; p->nElem++;
...@@ -437,13 +434,10 @@ void BigPtrArray::Remove( sal_uLong pos, sal_uLong n ) ...@@ -437,13 +434,10 @@ void BigPtrArray::Remove( sal_uLong pos, sal_uLong n )
void BigPtrArray::Replace( sal_uLong idx, const ElementPtr& rElem) void BigPtrArray::Replace( sal_uLong idx, const ElementPtr& rElem)
{ {
assert(idx < nSize); // Index out of bounds assert(idx < nSize); // Index out of bounds
// because this function ist not <const>: nCur = Index2Block( idx );
BigPtrArray* pThis = (BigPtrArray*) this; BlockInfo* p = ppInf[ nCur ];
sal_uInt16 cur = Index2Block( idx ); rElem->nOffset = sal_uInt16(idx - p->nStart);
BlockInfo* p = ppInf[ cur ]; rElem->pBlock = p;
pThis->nCur = cur;
((ElementPtr&)rElem)->nOffset = sal_uInt16(idx - p->nStart);
((ElementPtr&)rElem)->pBlock = p;
p->pData[ idx - p->nStart ] = rElem; p->pData[ idx - p->nStart ] = rElem;
} }
......
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