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

Noel Grandin noel.grandin at collabora.co.uk
Tue Jun 27 12:34:58 UTC 2017


 sw/inc/bparr.hxx                 |   22 ++++++++++++++--------
 sw/source/core/bastyp/bparr.cxx  |   39 +++++++++++++++++----------------------
 sw/source/core/docnode/nodes.cxx |    4 ++--
 3 files changed, 33 insertions(+), 32 deletions(-)

New commits:
commit b06657fca57b02ffb267a168bc9323780aeafbef
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Jun 27 13:42:01 2017 +0200

    use std::array in BlockInfo
    
    Change-Id: I28a13592e5993454ae96b0a32ba328013da7856e
    Reviewed-on: https://gerrit.libreoffice.org/39296
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/inc/bparr.hxx b/sw/inc/bparr.hxx
index 46260762b9d4..c51e959ada1d 100644
--- a/sw/inc/bparr.hxx
+++ b/sw/inc/bparr.hxx
@@ -24,6 +24,7 @@
 
 #include <tools/solar.h>
 #include <swdllapi.h>
+#include <array>
 
 struct BlockInfo;
 class BigPtrArray;
@@ -31,8 +32,8 @@ class BigPtrArray;
 class BigPtrEntry
 {
     friend class BigPtrArray;
-    BlockInfo* m_pBlock;
-    sal_uInt16 m_nOffset;
+    BlockInfo*  m_pBlock;
+    sal_uInt16  m_nOffset;
 public:
     BigPtrEntry() : m_pBlock(nullptr), m_nOffset(0) {}
     virtual ~BigPtrEntry() {}
@@ -50,11 +51,16 @@ public:
 // if complete compression is desired, 100 has to be specified
 #define COMPRESSLVL 80
 
-struct BlockInfo {
-    BigPtrArray* pBigArr;           ///< in this array the block is located
-    BigPtrEntry** pData;            ///< data block
-    sal_uLong nStart, nEnd;         ///< start- and end index
-    sal_uInt16 nElem;               ///< number of elements
+struct BlockInfo final
+{
+    BigPtrArray* const
+                 pBigArr;              ///< in this array the block is located
+    std::array<BigPtrEntry*, MAXENTRY>
+                 mvData;               ///< data block
+    sal_uLong    nStart, nEnd;         ///< start- and end index
+    sal_uInt16   nElem;                ///< number of elements
+
+    BlockInfo(BigPtrArray* b) : pBigArr(b) {}
 };
 
 class SW_DLLPUBLIC BigPtrArray
@@ -91,7 +97,7 @@ public:
 
 inline sal_uLong BigPtrEntry::GetPos() const
 {
-    assert(this == m_pBlock->pData[ m_nOffset ]); // element not in the block
+    assert(this == m_pBlock->mvData[ m_nOffset ]); // element not in the block
     return m_pBlock->nStart + m_nOffset;
 }
 
diff --git a/sw/source/core/bastyp/bparr.cxx b/sw/source/core/bastyp/bparr.cxx
index b0d62c7a6e9c..c5331bcf11d6 100644
--- a/sw/source/core/bastyp/bparr.cxx
+++ b/sw/source/core/bastyp/bparr.cxx
@@ -60,8 +60,7 @@ BigPtrArray::~BigPtrArray()
         BlockInfo** pp = m_ppInf;
         for( sal_uInt16 n = 0; n < m_nBlock; ++n, ++pp )
         {
-            delete[] (*pp)->pData;
-            delete    *pp;
+            delete *pp;
         }
     }
     delete[] m_ppInf;
@@ -75,7 +74,7 @@ void BigPtrArray::Move( sal_uLong from, sal_uLong to )
     {
         sal_uInt16 cur = Index2Block( from );
         BlockInfo* p = m_ppInf[ cur ];
-        BigPtrEntry* pElem = p->pData[ from - p->nStart ];
+        BigPtrEntry* pElem = p->mvData[ from - p->nStart ];
         Insert( pElem, to ); // insert first, then delete!
         Remove( ( to < from ) ? ( from + 1 ) : from );
     }
@@ -86,7 +85,7 @@ BigPtrEntry* BigPtrArray::operator[]( sal_uLong idx ) const
     assert(idx < m_nSize); // operator[]: Index out of bounds
     m_nCur = Index2Block( idx );
     BlockInfo* p = m_ppInf[ m_nCur ];
-    return p->pData[ idx - p->nStart ];
+    return p->mvData[ idx - p->nStart ];
 }
 
 /** Search a block at a given position */
@@ -173,7 +172,7 @@ BlockInfo* BigPtrArray::InsBlock( sal_uInt16 pos )
                  ( m_nBlock - pos ) * sizeof( BlockInfo* ));
     }
     ++m_nBlock;
-    BlockInfo* p = new BlockInfo;
+    BlockInfo* p = new BlockInfo(this);
     m_ppInf[ pos ] = p;
 
     if( pos )
@@ -183,8 +182,6 @@ BlockInfo* BigPtrArray::InsBlock( sal_uInt16 pos )
 
     p->nEnd--;  // no elements
     p->nElem = 0;
-    p->pData = new BigPtrEntry* [ MAXENTRY ];
-    p->pBigArr = this;
     return p;
 }
 
@@ -240,8 +237,8 @@ void BigPtrArray::Insert( BigPtrEntry* pElem, sal_uLong pos )
             if( q->nElem )
             {
                 int nCount = q->nElem;
-                BigPtrEntry** pFrom = q->pData + nCount;
-                BigPtrEntry** pTo   = pFrom + 1;
+                auto pFrom = q->mvData.begin() + nCount;
+                auto pTo   = pFrom + 1;
                 while( nCount-- )
                     ++( *--pTo = *--pFrom )->m_nOffset;
             }
@@ -266,11 +263,11 @@ void BigPtrArray::Insert( BigPtrEntry* pElem, sal_uLong pos )
         }
 
         // entry does not fit anymore - clear space
-        BigPtrEntry* pLast = p->pData[ MAXENTRY-1 ];
+        BigPtrEntry* pLast = p->mvData[ MAXENTRY-1 ];
         pLast->m_nOffset = 0;
         pLast->m_pBlock = q;
 
-        q->pData[ 0 ] = pLast;
+        q->mvData[ 0 ] = pLast;
         q->nElem++;
         q->nEnd++;
 
@@ -283,15 +280,15 @@ void BigPtrArray::Insert( BigPtrEntry* pElem, sal_uLong pos )
     if( pos != p->nElem )
     {
         int nCount = p->nElem - sal_uInt16(pos);
-        BigPtrEntry* *pFrom = p->pData + p->nElem;
-        BigPtrEntry* *pTo   = pFrom + 1;
+        auto pFrom = p->mvData.begin() + p->nElem;
+        auto pTo   = pFrom + 1;
         while( nCount-- )
             ++( *--pTo = *--pFrom )->m_nOffset;
     }
     // insert element and update indices
     pElem->m_nOffset = sal_uInt16(pos);
     pElem->m_pBlock = p;
-    p->pData[ pos ] = pElem;
+    p->mvData[ pos ] = pElem;
     p->nEnd++;
     p->nElem++;
     m_nSize++;
@@ -321,8 +318,8 @@ void BigPtrArray::Remove( sal_uLong pos, sal_uLong n )
         // move elements if needed
         if( ( pos + nel ) < sal_uLong(p->nElem) )
         {
-            BigPtrEntry* *pTo = p->pData + pos;
-            BigPtrEntry* *pFrom = pTo + nel;
+            auto pTo = p->mvData.begin() + pos;
+            auto pFrom = pTo + nel;
             int nCount = p->nElem - nel - sal_uInt16(pos);
             while( nCount-- )
             {
@@ -336,7 +333,6 @@ void BigPtrArray::Remove( sal_uLong pos, sal_uLong n )
         // possibly delete block completely
         if( !p->nElem )
         {
-            delete[] p->pData;
             nBlkdel++;
             if( USHRT_MAX == nBlk1del )
                 nBlk1del = cur;
@@ -393,7 +389,7 @@ void BigPtrArray::Replace( sal_uLong idx, BigPtrEntry* pElem)
     BlockInfo* p = m_ppInf[ m_nCur ];
     pElem->m_nOffset = sal_uInt16(idx - p->nStart);
     pElem->m_pBlock = p;
-    p->pData[ idx - p->nStart ] = pElem;
+    p->mvData[ idx - p->nStart ] = pElem;
 }
 
 /** Compress the array */
@@ -434,8 +430,8 @@ sal_uInt16 BigPtrArray::Compress()
                 n = nLast;
 
             // move elements from current to last block
-            BigPtrEntry** pElem = pLast->pData + pLast->nElem;
-            BigPtrEntry** pFrom = p->pData;
+            auto pElem = pLast->mvData.begin() + pLast->nElem;
+            auto pFrom = p->mvData.begin();
             for( sal_uInt16 nCount = n, nOff = pLast->nElem;
                             nCount; --nCount, ++pElem )
             {
@@ -453,14 +449,13 @@ sal_uInt16 BigPtrArray::Compress()
             if( !p->nElem )
             {
                 // than remove
-                delete[] p->pData;
                 delete   p;
                 p = nullptr;
                 ++nBlkdel;
             }
             else
             {
-                pElem = p->pData;
+                pElem = p->mvData.begin();
                 pFrom = pElem + n;
                 int nCount = p->nElem;
                 while( nCount-- )
diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx
index 123062b86c1c..7d509998ba63 100644
--- a/sw/source/core/docnode/nodes.cxx
+++ b/sw/source/core/docnode/nodes.cxx
@@ -2188,7 +2188,7 @@ void SwNodes::ForEach( sal_uLong nStart, sal_uLong nEnd,
         BlockInfo** pp = m_ppInf + cur;
         BlockInfo* p = *pp;
         sal_uInt16 nElem = sal_uInt16( nStart - p->nStart );
-        BigPtrEntry** pElem = p->pData + nElem;
+        auto pElem = p->mvData.begin() + nElem;
         nElem = p->nElem - nElem;
         for(;;)
         {
@@ -2200,7 +2200,7 @@ void SwNodes::ForEach( sal_uLong nStart, sal_uLong nEnd,
             {
                 // new block
                 p = *++pp;
-                pElem = p->pData;
+                pElem = p->mvData.begin();
                 nElem = p->nElem;
             }
         }


More information about the Libreoffice-commits mailing list