[Libreoffice-commits] core.git: sdext/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Dec 21 17:51:34 UTC 2018


 sdext/source/pdfimport/inc/pdfparse.hxx        |    2 +-
 sdext/source/pdfimport/pdfparse/pdfentries.cxx |   24 +++++++++++++++---------
 2 files changed, 16 insertions(+), 10 deletions(-)

New commits:
commit 725b5863832ef712d05b3cd49b77d447d84b80bb
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Dec 21 11:22:01 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Dec 21 18:51:01 2018 +0100

    use unique_ptr in sdext
    
    Change-Id: I8362cf42dd6a838752b25a4b184da614eb81805e
    Reviewed-on: https://gerrit.libreoffice.org/65532
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sdext/source/pdfimport/inc/pdfparse.hxx b/sdext/source/pdfimport/inc/pdfparse.hxx
index e5d9dcc9bef0..e8fcd77f7863 100644
--- a/sdext/source/pdfimport/inc/pdfparse.hxx
+++ b/sdext/source/pdfimport/inc/pdfparse.hxx
@@ -191,7 +191,7 @@ struct PDFDict : public PDFContainer
 
     // inserting a value of NULL will remove rName and the previous value
     // from the dictionary
-    void insertValue( const OString& rName, PDFEntry* pValue );
+    void insertValue( const OString& rName, std::unique_ptr<PDFEntry> pValue );
     // removes a name/value pair from the dict
     void eraseValue( const OString& rName );
     // builds new map as of sub elements
diff --git a/sdext/source/pdfimport/pdfparse/pdfentries.cxx b/sdext/source/pdfimport/pdfparse/pdfentries.cxx
index 7bc541c3b1bd..97ef24917cb4 100644
--- a/sdext/source/pdfimport/pdfparse/pdfentries.cxx
+++ b/sdext/source/pdfimport/pdfparse/pdfentries.cxx
@@ -523,26 +523,32 @@ bool PDFDict::emit( EmitContext& rWriteContext ) const
     return rWriteContext.write( "\n>>\n", 4 );
 }
 
-void PDFDict::insertValue( const OString& rName, PDFEntry* pValue )
+void PDFDict::insertValue( const OString& rName, std::unique_ptr<PDFEntry> pValue )
 {
     if( ! pValue )
         eraseValue( rName );
 
+    auto pValueTmp = pValue.get();
     std::unordered_map<OString,PDFEntry*>::iterator it = m_aMap.find( rName );
     if( it == m_aMap.end() )
     {
         // new name/value, pair, append it
         m_aSubElements.emplace_back(o3tl::make_unique<PDFName>(rName));
-        m_aSubElements.emplace_back( pValue );
+        m_aSubElements.emplace_back( std::move(pValue) );
     }
     else
     {
         unsigned int nSub = m_aSubElements.size();
-        for( unsigned int i = 0; i < nSub; i++ )
+        bool bFound = false;
+        for( unsigned int i = 0; i < nSub && !bFound; i++ )
             if( m_aSubElements[i].get() == it->second )
-                m_aSubElements[i].reset(pValue);
+            {
+                m_aSubElements[i] = std::move(pValue);
+                bFound = true;
+                break;
+            }
     }
-    m_aMap[ rName ] = pValue;
+    m_aMap[ rName ] = pValueTmp;
 }
 
 void PDFDict::eraseValue( const OString& rName )
@@ -833,10 +839,10 @@ bool PDFObject::emit( EmitContext& rWriteContext ) const
             if( nOutBytes )
             {
                 // clone this object
-                PDFObject* pClone = static_cast<PDFObject*>(clone());
+                std::unique_ptr<PDFObject> pClone(static_cast<PDFObject*>(clone()));
                 // set length in the dictionary to new stream length
-                PDFNumber* pNewLen = new PDFNumber( double(nOutBytes) );
-                pClone->m_pStream->m_pDict->insertValue( "Length", pNewLen );
+                std::unique_ptr<PDFNumber> pNewLen(new PDFNumber( double(nOutBytes) ));
+                pClone->m_pStream->m_pDict->insertValue( "Length", std::move(pNewLen) );
 
                 if( bDeflate && rWriteContext.m_bDeflate )
                 {
@@ -871,7 +877,7 @@ bool PDFObject::emit( EmitContext& rWriteContext ) const
                     if( pClone->m_aSubElements[i].get() != pClone->m_pStream )
                         bRet = pClone->m_aSubElements[i]->emit( rWriteContext );
                 }
-                delete pClone;
+                pClone.reset();
                 // write stream
                 if( bRet )
                     bRet = rWriteContext.write("stream\n", 7)


More information about the Libreoffice-commits mailing list