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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Dec 19 11:34:27 UTC 2018


 scripting/source/stringresource/stringresource.cxx |   44 +++++++++------------
 scripting/source/stringresource/stringresource.hxx |    2 
 2 files changed, 20 insertions(+), 26 deletions(-)

New commits:
commit f12b6893cfee3df23756f752adad299f1368f04b
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Dec 19 10:52:51 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Dec 19 12:34:05 2018 +0100

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

diff --git a/scripting/source/stringresource/stringresource.cxx b/scripting/source/stringresource/stringresource.cxx
index bb700290ff25..bf4260646caa 100644
--- a/scripting/source/stringresource/stringresource.cxx
+++ b/scripting/source/stringresource/stringresource.cxx
@@ -38,6 +38,7 @@
 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
 
 #include <osl/diagnose.h>
+#include <o3tl/make_unique.hxx>
 #include <rtl/tencinfo.h>
 #include <rtl/ustrbuf.hxx>
 #include <rtl/strbuf.hxx>
@@ -337,8 +338,8 @@ void StringResourceImpl::setDefaultLocale( const Locale& locale )
     {
         if( m_pDefaultLocaleItem )
         {
-            LocaleItem* pChangedDefaultLocaleItem = new LocaleItem( m_pDefaultLocaleItem->m_locale );
-            m_aChangedDefaultLocaleVector.push_back( pChangedDefaultLocaleItem );
+            m_aChangedDefaultLocaleVector.push_back(
+                o3tl::make_unique<LocaleItem>( m_pDefaultLocaleItem->m_locale ) );
         }
 
         m_pDefaultLocaleItem = pLocaleItem;
@@ -523,8 +524,8 @@ void StringResourceImpl::removeLocale( const Locale& locale )
                     m_nNextUniqueNumericId = 0;
                     if( m_pDefaultLocaleItem )
                     {
-                        LocaleItem* pChangedDefaultLocaleItem = new LocaleItem( m_pDefaultLocaleItem->m_locale );
-                        m_aChangedDefaultLocaleVector.push_back( pChangedDefaultLocaleItem );
+                        m_aChangedDefaultLocaleVector.push_back(
+                                o3tl::make_unique<LocaleItem>( m_pDefaultLocaleItem->m_locale ) );
                     }
                     m_pCurrentLocaleItem = nullptr;
                     m_pDefaultLocaleItem = nullptr;
@@ -937,20 +938,17 @@ void StringResourcePersistenceImpl::implStoreAtStorage
     {
         for( auto& pLocaleItem : m_aChangedDefaultLocaleVector )
         {
-            if( pLocaleItem != nullptr )
-            {
-                OUString aStreamName = implGetFileNameForLocaleItem( pLocaleItem, m_aNameBase );
-                aStreamName += ".default";
-
-                try
-                {
-                    Storage->removeElement( aStreamName );
-                }
-                catch( Exception& )
-                {}
+            OUString aStreamName = implGetFileNameForLocaleItem( pLocaleItem.get(), m_aNameBase );
+            aStreamName += ".default";
 
-                delete pLocaleItem;
+            try
+            {
+                Storage->removeElement( aStreamName );
             }
+            catch( Exception& )
+            {}
+
+            pLocaleItem.reset();
         }
         m_aChangedDefaultLocaleVector.clear();
     }
@@ -1019,15 +1017,11 @@ void StringResourcePersistenceImpl::implKillChangedDefaultFiles
     // Delete files for changed defaults
     for( auto& pLocaleItem : m_aChangedDefaultLocaleVector )
     {
-        if( pLocaleItem != nullptr )
-        {
-            OUString aCompleteFileName =
-                implGetPathForLocaleItem( pLocaleItem, aNameBase, Location, true );
-            if( xFileAccess->exists( aCompleteFileName ) )
-                xFileAccess->kill( aCompleteFileName );
-
-            delete pLocaleItem;
-        }
+        OUString aCompleteFileName =
+            implGetPathForLocaleItem( pLocaleItem.get(), aNameBase, Location, true );
+        if( xFileAccess->exists( aCompleteFileName ) )
+            xFileAccess->kill( aCompleteFileName );
+        pLocaleItem.reset();
     }
     m_aChangedDefaultLocaleVector.clear();
 }
diff --git a/scripting/source/stringresource/stringresource.hxx b/scripting/source/stringresource/stringresource.hxx
index e99088b001cf..13ad55a327ec 100644
--- a/scripting/source/stringresource/stringresource.hxx
+++ b/scripting/source/stringresource/stringresource.hxx
@@ -82,7 +82,7 @@ struct LocaleItem
     {}
 };
 
-typedef std::vector< LocaleItem* > LocaleItemVector;
+typedef std::vector< std::unique_ptr<LocaleItem> > LocaleItemVector;
 
 typedef ::cppu::WeakImplHelper<
     css::lang::XServiceInfo,


More information about the Libreoffice-commits mailing list