[Libreoffice-commits] core.git: 3 commits - filter/source

Noel Grandin noel.grandin at collabora.co.uk
Mon May 7 06:32:36 UTC 2018


 filter/source/graphicfilter/egif/giflzwc.cxx |   15 +++++++--------
 filter/source/graphicfilter/egif/giflzwc.hxx |    4 ++--
 filter/source/graphicfilter/etiff/etiff.cxx  |   12 ++++++------
 filter/source/graphicfilter/icgm/bundles.cxx |   18 ++++++++----------
 filter/source/graphicfilter/icgm/bundles.hxx |    2 +-
 5 files changed, 24 insertions(+), 27 deletions(-)

New commits:
commit 945642c28971efc89d3bbc5e474814b19ba2a76c
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu May 3 15:08:26 2018 +0200

    loplugin:useuniqueptr in CGMFList
    
    Change-Id: I2ad0995c9ef9e04efb4ee3dad9c1a879303c8dbd
    Reviewed-on: https://gerrit.libreoffice.org/53873
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/filter/source/graphicfilter/icgm/bundles.cxx b/filter/source/graphicfilter/icgm/bundles.cxx
index 13bddfdcf0ec..3b0fb067b877 100644
--- a/filter/source/graphicfilter/icgm/bundles.cxx
+++ b/filter/source/graphicfilter/icgm/bundles.cxx
@@ -112,9 +112,9 @@ CGMFList& CGMFList::operator=( const CGMFList& rSource )
     nFontsAvailable = rSource.nFontsAvailable;
     nFontNameCount  = rSource.nFontNameCount;
     nCharSetCount   = rSource.nCharSetCount;
-    for (FontEntry* pPtr : rSource.aFontEntryList)
+    for (auto const & pPtr : rSource.aFontEntryList)
     {
-        FontEntry* pCFontEntry = new FontEntry;
+        std::unique_ptr<FontEntry> pCFontEntry(new FontEntry);
         if ( pPtr->pFontName )
         {
             sal_uInt32 nSize = strlen( reinterpret_cast<char*>(pPtr->pFontName.get()) ) + 1;
@@ -129,7 +129,7 @@ CGMFList& CGMFList::operator=( const CGMFList& rSource )
         }
         pCFontEntry->eCharSetType = pPtr->eCharSetType;
         pCFontEntry->nFontType = pPtr->nFontType;
-        aFontEntryList.push_back( pCFontEntry );
+        aFontEntryList.push_back( std::move(pCFontEntry) );
     }
     return *this;
 }
@@ -140,7 +140,7 @@ FontEntry* CGMFList::GetFontEntry( sal_uInt32 nIndex )
     sal_uInt32 nInd = nIndex;
     if ( nInd )
         nInd--;
-    return ( nInd < aFontEntryList.size() ) ? aFontEntryList[ nInd ] : nullptr;
+    return ( nInd < aFontEntryList.size() ) ? aFontEntryList[ nInd ].get() : nullptr;
 }
 
 
@@ -168,11 +168,11 @@ void CGMFList::InsertName( sal_uInt8 const * pSource, sal_uInt32 nSize )
     {
         nFontsAvailable++;
         pFontEntry = new FontEntry;
-        aFontEntryList.push_back( pFontEntry );
+        aFontEntryList.push_back( std::unique_ptr<FontEntry>(pFontEntry) );
     }
     else
     {
-        pFontEntry = aFontEntryList[ nFontNameCount ];
+        pFontEntry = aFontEntryList[ nFontNameCount ].get();
     }
     nFontNameCount++;
     std::unique_ptr<sal_Int8[]> pBuf(new sal_Int8[ nSize ]);
@@ -229,11 +229,11 @@ void CGMFList::InsertCharSet( CharSetType eCharSetType, sal_uInt8 const * pSourc
     {
         nFontsAvailable++;
         pFontEntry = new FontEntry;
-        aFontEntryList.push_back( pFontEntry );
+        aFontEntryList.push_back( std::unique_ptr<FontEntry>(pFontEntry) );
     }
     else
     {
-        pFontEntry = aFontEntryList[ nCharSetCount ];
+        pFontEntry = aFontEntryList[ nCharSetCount ].get();
     }
     nCharSetCount++;
     pFontEntry->eCharSetType = eCharSetType;
@@ -245,8 +245,6 @@ void CGMFList::InsertCharSet( CharSetType eCharSetType, sal_uInt8 const * pSourc
 
 void CGMFList::ImplDeleteList()
 {
-    for (FontEntry* i : aFontEntryList)
-        delete i;
     aFontEntryList.clear();
 }
 
diff --git a/filter/source/graphicfilter/icgm/bundles.hxx b/filter/source/graphicfilter/icgm/bundles.hxx
index 51e92567a534..cf1516e2c5a1 100644
--- a/filter/source/graphicfilter/icgm/bundles.hxx
+++ b/filter/source/graphicfilter/icgm/bundles.hxx
@@ -159,7 +159,7 @@ class CGMFList
 {
     sal_uInt32      nFontNameCount;
     sal_uInt32      nCharSetCount;
-    ::std::vector< FontEntry* >
+    ::std::vector< std::unique_ptr<FontEntry> >
                     aFontEntryList;
     void            ImplDeleteList();
 
commit 2834d503d683c7a125b24e49f0127d43cb2501e9
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu May 3 15:05:21 2018 +0200

    loplugin:useuniqueptr in TIFFWriter
    
    Change-Id: I119e280f43e38c9ada64ce5a59dcee2aa0dc2e94
    Reviewed-on: https://gerrit.libreoffice.org/53872
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/filter/source/graphicfilter/etiff/etiff.cxx b/filter/source/graphicfilter/etiff/etiff.cxx
index 643f44031fb0..9663cb669abc 100644
--- a/filter/source/graphicfilter/etiff/etiff.cxx
+++ b/filter/source/graphicfilter/etiff/etiff.cxx
@@ -79,7 +79,7 @@ private:
     sal_uInt32              mnBitmapPos;
     sal_uInt32              mnStripByteCountPos;
 
-    TIFFLZWCTreeNode*       pTable;
+    std::unique_ptr<TIFFLZWCTreeNode[]> pTable;
     TIFFLZWCTreeNode*       pPrefix;
     sal_uInt16              nDataSize;
     sal_uInt16              nClearCode;
@@ -499,7 +499,7 @@ void TIFFWriter::StartCompression()
     nOffset = 32;                       // number of free bits in dwShift
     dwShift = 0;
 
-    pTable = new TIFFLZWCTreeNode[ 4096 ];
+    pTable.reset(new TIFFLZWCTreeNode[ 4096 ]);
 
     for ( i = 0; i < 4096; i++)
     {
@@ -520,7 +520,7 @@ void TIFFWriter::Compress( sal_uInt8 nCompThis )
 
     if( !pPrefix )
     {
-        pPrefix = pTable + nCompThis;
+        pPrefix = &pTable[nCompThis];
     }
     else
     {
@@ -552,14 +552,14 @@ void TIFFWriter::Compress( sal_uInt8 nCompThis )
                 if( nTableSize == static_cast<sal_uInt16>( ( 1 << nCodeSize ) - 1 ) )
                     nCodeSize++;
 
-                p = pTable + ( nTableSize++ );
+                p = &pTable[ nTableSize++ ];
                 p->pBrother = pPrefix->pFirstChild;
                 pPrefix->pFirstChild = p;
                 p->nValue = nV;
                 p->pFirstChild = nullptr;
             }
 
-            pPrefix = pTable + nV;
+            pPrefix = &pTable[nV];
         }
     }
 }
@@ -571,7 +571,7 @@ void TIFFWriter::EndCompression()
         WriteBits( pPrefix->nCode, nCodeSize );
 
     WriteBits( nEOICode, nCodeSize );
-    delete[] pTable;
+    pTable.reset();
 }
 
 
commit 6e155026b1c123045def6e1a72ac268e78b4262e
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu May 3 15:03:14 2018 +0200

    loplugin:useuniqueptr in GIFLZWCompressor
    
    Change-Id: Iffc9cab9717691818bdc49c8a97f0dff9461340d
    Reviewed-on: https://gerrit.libreoffice.org/53871
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/filter/source/graphicfilter/egif/giflzwc.cxx b/filter/source/graphicfilter/egif/giflzwc.cxx
index a660007c7a36..5a4601d38c9e 100644
--- a/filter/source/graphicfilter/egif/giflzwc.cxx
+++ b/filter/source/graphicfilter/egif/giflzwc.cxx
@@ -139,8 +139,8 @@ void GIFLZWCompressor::StartCompression( SvStream& rGIF, sal_uInt16 nPixelSize )
         nTableSize=nEOICode+1;
         nCodeSize=nDataSize+1;
 
-        pIDOS=new GIFImageDataOutputStream(rGIF,static_cast<sal_uInt8>(nDataSize));
-        pTable=new GIFLZWCTreeNode[4096];
+        pIDOS.reset(new GIFImageDataOutputStream(rGIF,static_cast<sal_uInt8>(nDataSize)));
+        pTable.reset(new GIFLZWCTreeNode[4096]);
 
         for (i=0; i<4096; i++)
         {
@@ -163,7 +163,7 @@ void GIFLZWCompressor::Compress(sal_uInt8* pSrc, sal_uInt32 nSize)
 
         if( !pPrefix && nSize )
         {
-            pPrefix=pTable+(*pSrc++);
+            pPrefix=&pTable[*pSrc++];
             nSize--;
         }
 
@@ -198,14 +198,14 @@ void GIFLZWCompressor::Compress(sal_uInt8* pSrc, sal_uInt32 nSize)
                     if(nTableSize==static_cast<sal_uInt16>(1<<nCodeSize))
                         nCodeSize++;
 
-                    p=pTable+(nTableSize++);
+                    p=&pTable[nTableSize++];
                     p->pBrother=pPrefix->pFirstChild;
                     pPrefix->pFirstChild=p;
                     p->nValue=nV;
                     p->pFirstChild=nullptr;
                 }
 
-                pPrefix=pTable+nV;
+                pPrefix=&pTable[nV];
             }
         }
     }
@@ -219,9 +219,8 @@ void GIFLZWCompressor::EndCompression()
             pIDOS->WriteBits(pPrefix->nCode,nCodeSize);
 
         pIDOS->WriteBits( nEOICode,nCodeSize );
-        delete[] pTable;
-        delete pIDOS;
-        pIDOS=nullptr;
+        pTable.reset();
+        pIDOS.reset();
     }
 }
 
diff --git a/filter/source/graphicfilter/egif/giflzwc.hxx b/filter/source/graphicfilter/egif/giflzwc.hxx
index 0c51ff55d7b8..018a45812646 100644
--- a/filter/source/graphicfilter/egif/giflzwc.hxx
+++ b/filter/source/graphicfilter/egif/giflzwc.hxx
@@ -31,8 +31,8 @@ class GIFLZWCompressor
 {
 private:
 
-    GIFImageDataOutputStream*   pIDOS;
-    GIFLZWCTreeNode*            pTable;
+    std::unique_ptr<GIFImageDataOutputStream> pIDOS;
+    std::unique_ptr<GIFLZWCTreeNode[]> pTable;
     GIFLZWCTreeNode*            pPrefix;
     sal_uInt16                  nDataSize;
     sal_uInt16                  nClearCode;


More information about the Libreoffice-commits mailing list