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

Noel Grandin noel.grandin at collabora.co.uk
Thu Jan 25 06:23:52 UTC 2018


 xmloff/inc/XMLEventImportHelper.hxx           |    5 -
 xmloff/source/draw/sdxmlexp.cxx               |   79 +++++++-------------------
 xmloff/source/draw/sdxmlexp_impl.hxx          |    9 +-
 xmloff/source/script/XMLEventImportHelper.cxx |    9 +-
 4 files changed, 34 insertions(+), 68 deletions(-)

New commits:
commit 437fffe098429dcc2c65184876b6b8444a7d452c
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Jan 17 16:57:13 2018 +0200

    loplugin:useuniqueptr in SdXMLExport
    
    and flatten some data structures, no need to allocate some of the the
    vector members on the heap
    
    Change-Id: I8e7e06144da2fa58c8e3352013d44d368d61ea1d
    Reviewed-on: https://gerrit.libreoffice.org/48480
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/xmloff/source/draw/sdxmlexp.cxx b/xmloff/source/draw/sdxmlexp.cxx
index 44021c381ac9..68f34762be7b 100644
--- a/xmloff/source/draw/sdxmlexp.cxx
+++ b/xmloff/source/draw/sdxmlexp.cxx
@@ -392,11 +392,7 @@ SdXMLExport::SdXMLExport(
     mnDocMasterPageCount(0),
     mnDocDrawPageCount(0),
     mnObjectCount(0),
-    mpPageMasterInfoList(new ImpXMLEXPPageMasterList),
-    mpPageMasterUsageList(new ImpXMLEXPPageMasterList),
-    mpNotesPageMasterUsageList(new ImpXMLEXPPageMasterList),
     mpHandoutPageMaster(nullptr),
-    mpAutoLayoutInfoList(new ImpXMLAutoLayoutInfoList),
     mbIsDraw(bIsDraw),
     msPageLayoutNames( "PageLayoutNames" )
 {
@@ -641,39 +637,10 @@ SdXMLExport::~SdXMLExport()
     // cleanup presPage mapper, decrease refcount. Should lead to destruction.
     mpPresPagePropsMapper.clear();
 
-    // clear evtl. temporary page master infos
-    if(mpPageMasterUsageList)
-    {
-        // note: all items in this list are also in mpPageMasterInfoList
-        delete mpPageMasterUsageList;
-        mpPageMasterUsageList = nullptr;
-    }
-
-    if(mpNotesPageMasterUsageList)
-    {
-        // note: all items in this list are also in mpPageMasterInfoList
-        delete mpNotesPageMasterUsageList;
-        mpNotesPageMasterUsageList = nullptr;
-    }
-
-    if(mpPageMasterInfoList)
-    {
-        for (ImpXMLEXPPageMasterInfo* p : *mpPageMasterInfoList)
-            delete p;
-        mpPageMasterInfoList->clear();
-        delete mpPageMasterInfoList;
-        mpPageMasterInfoList = nullptr;
-    }
+    mvPageMasterInfoList.clear();
 
     // clear auto-layout infos
-    if(mpAutoLayoutInfoList)
-    {
-        for (ImpXMLAutoLayoutInfo* p : *mpAutoLayoutInfoList)
-            delete p;
-        mpAutoLayoutInfoList->clear();
-        delete mpAutoLayoutInfoList;
-        mpAutoLayoutInfoList = nullptr;
-    }
+    mvAutoLayoutInfoList.clear();
 }
 
 void SdXMLExport::ImpPrepAutoLayoutInfos()
@@ -746,21 +713,21 @@ bool SdXMLExport::ImpPrepAutoLayoutInfo(const Reference<XDrawPage>& xPage, OUStr
                 ImpXMLAutoLayoutInfo* pNew = new ImpXMLAutoLayoutInfo(nType, pInfo);
                 bool bDidExist(false);
 
-                for( size_t nCnt = 0; !bDidExist && nCnt < mpAutoLayoutInfoList->size(); nCnt++)
+                for( size_t nCnt = 0; !bDidExist && nCnt < mvAutoLayoutInfoList.size(); nCnt++)
                 {
-                    if( *mpAutoLayoutInfoList->at( nCnt ) == *pNew)
+                    if( *mvAutoLayoutInfoList.at( nCnt ) == *pNew)
                     {
                         delete pNew;
-                        pNew = mpAutoLayoutInfoList->at( nCnt );
+                        pNew = mvAutoLayoutInfoList.at( nCnt ).get();
                         bDidExist = true;
                     }
                 }
 
                 if(!bDidExist)
                 {
-                    mpAutoLayoutInfoList->push_back( pNew );
+                    mvAutoLayoutInfoList.emplace_back( pNew );
                     OUString sNewName = "AL";
-                    sNewName += OUString::number(mpAutoLayoutInfoList->size() - 1);
+                    sNewName += OUString::number(mvAutoLayoutInfoList.size() - 1);
                     sNewName += "T";
                     sNewName += OUString::number(nType);
                     pNew->SetLayoutName(sNewName);
@@ -777,9 +744,9 @@ bool SdXMLExport::ImpPrepAutoLayoutInfo(const Reference<XDrawPage>& xPage, OUStr
 
 void SdXMLExport::ImpWriteAutoLayoutInfos()
 {
-    if( !mpAutoLayoutInfoList->empty() )
+    if( !mvAutoLayoutInfoList.empty() )
     {
-        for(ImpXMLAutoLayoutInfo* pInfo : *mpAutoLayoutInfoList)
+        for(auto & pInfo : mvAutoLayoutInfoList)
         {
             if(pInfo)
             {
@@ -1217,20 +1184,20 @@ ImpXMLEXPPageMasterInfo* SdXMLExport::ImpGetOrCreatePageMasterInfo( const Refere
     ImpXMLEXPPageMasterInfo* pNewInfo = new ImpXMLEXPPageMasterInfo(*this, xMasterPage);
 
     // compare with prev page-master infos
-    for( size_t a = 0; !bDoesExist && a < mpPageMasterInfoList->size(); a++)
+    for( size_t a = 0; !bDoesExist && a < mvPageMasterInfoList.size(); a++)
     {
-        if (   mpPageMasterInfoList->at(a)
-           && *mpPageMasterInfoList->at(a) == *pNewInfo
+        if (   mvPageMasterInfoList.at(a)
+           && *mvPageMasterInfoList.at(a) == *pNewInfo
            )
         {
             delete pNewInfo;
-            pNewInfo = mpPageMasterInfoList->at(a);
+            pNewInfo = mvPageMasterInfoList.at(a).get();
             bDoesExist = true;
         }
     }
     // add entry when not found same page-master infos
     if(!bDoesExist)
-        mpPageMasterInfoList->push_back( pNewInfo );
+        mvPageMasterInfoList.emplace_back( pNewInfo );
 
     return pNewInfo;
 }
@@ -1262,7 +1229,7 @@ void SdXMLExport::ImpPrepPageMasterInfos()
             if(xMasterPage.is())
                 pNewInfo = ImpGetOrCreatePageMasterInfo(xMasterPage);
 
-            mpPageMasterUsageList->push_back( pNewInfo );
+            mvPageMasterUsageList.push_back( pNewInfo );
 
             // look for page master of handout page
             if(IsImpress())
@@ -1277,7 +1244,7 @@ void SdXMLExport::ImpPrepPageMasterInfos()
                         pNewInfo = ImpGetOrCreatePageMasterInfo(xNotesPage);
                     }
                 }
-                mpNotesPageMasterUsageList->push_back( pNewInfo );
+                mvNotesPageMasterUsageList.push_back( pNewInfo );
             }
         }
     }
@@ -1286,9 +1253,9 @@ void SdXMLExport::ImpPrepPageMasterInfos()
 void SdXMLExport::ImpWritePageMasterInfos()
 {
     // write created page-masters, create names for these
-    for( size_t nCnt = 0; nCnt < mpPageMasterInfoList->size(); nCnt++)
+    for( size_t nCnt = 0; nCnt < mvPageMasterInfoList.size(); nCnt++)
     {
-        ImpXMLEXPPageMasterInfo* pInfo = mpPageMasterInfoList->at(nCnt);
+        ImpXMLEXPPageMasterInfo* pInfo = mvPageMasterInfoList.at(nCnt).get();
         if(pInfo)
         {
             // create name
@@ -1351,15 +1318,15 @@ void SdXMLExport::ImpWritePageMasterInfos()
 
 ImpXMLEXPPageMasterInfo* SdXMLExport::ImpGetPageMasterInfoByName(const OUString& rName)
 {
-    if(!rName.isEmpty() && !mpPageMasterInfoList->empty())
+    if(!rName.isEmpty() && !mvPageMasterInfoList.empty())
     {
-        for(ImpXMLEXPPageMasterInfo* pInfo : *mpPageMasterInfoList)
+        for(auto & pInfo : mvPageMasterInfoList)
         {
             if(pInfo)
             {
                 if(!pInfo->GetMasterPageName().isEmpty() && rName == pInfo->GetMasterPageName())
                 {
-                    return pInfo;
+                    return pInfo.get();
                 }
             }
         }
@@ -2373,7 +2340,7 @@ void SdXMLExport::ExportMasterStyles_()
                         sMasterPageName );
             }
 
-            ImpXMLEXPPageMasterInfo* pInfo = mpPageMasterUsageList->at( nMPageId );
+            ImpXMLEXPPageMasterInfo* pInfo = mvPageMasterUsageList.at( nMPageId );
             if(pInfo)
             {
                 OUString sString = pInfo->GetName();
@@ -2408,7 +2375,7 @@ void SdXMLExport::ExportMasterStyles_()
                         Reference< drawing::XShapes > xShapes(xNotesPage, UNO_QUERY);
                         if(xShapes.is())
                         {
-                            ImpXMLEXPPageMasterInfo* pMasterInfo = mpNotesPageMasterUsageList->at( nMPageId );
+                            ImpXMLEXPPageMasterInfo* pMasterInfo = mvNotesPageMasterUsageList.at( nMPageId );
                             if(pMasterInfo)
                             {
                                 OUString sString = pMasterInfo->GetName();
diff --git a/xmloff/source/draw/sdxmlexp_impl.hxx b/xmloff/source/draw/sdxmlexp_impl.hxx
index 22792d521e38..f583c0ee9e2e 100644
--- a/xmloff/source/draw/sdxmlexp_impl.hxx
+++ b/xmloff/source/draw/sdxmlexp_impl.hxx
@@ -38,7 +38,6 @@ class XMLShapeExportPropertyMapper;
 class XMLPageExportPropertyMapper;
 
 typedef ::std::vector< ImpXMLEXPPageMasterInfo* > ImpXMLEXPPageMasterList;
-typedef ::std::vector< ImpXMLAutoLayoutInfo*    > ImpXMLAutoLayoutInfoList;
 
 enum XmlPlaceholder
 {
@@ -82,11 +81,11 @@ class SdXMLExport : public SvXMLExport
     sal_uInt32                  mnObjectCount;
 
     // temporary infos
-    ImpXMLEXPPageMasterList*    mpPageMasterInfoList;
-    ImpXMLEXPPageMasterList*    mpPageMasterUsageList;
-    ImpXMLEXPPageMasterList*    mpNotesPageMasterUsageList;
+    std::vector< std::unique_ptr<ImpXMLEXPPageMasterInfo> > mvPageMasterInfoList;
+    ImpXMLEXPPageMasterList     mvPageMasterUsageList;
+    ImpXMLEXPPageMasterList     mvNotesPageMasterUsageList;
     ImpXMLEXPPageMasterInfo*    mpHandoutPageMaster;
-    ImpXMLAutoLayoutInfoList*   mpAutoLayoutInfoList;
+    std::vector< std::unique_ptr<ImpXMLAutoLayoutInfo> >    mvAutoLayoutInfoList;
 
     css::uno::Sequence< OUString > maDrawPagesAutoLayoutNames;
 
commit aae1a702696f485a418fbf53500977b236976d38
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Jan 17 15:59:54 2018 +0200

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

diff --git a/xmloff/inc/XMLEventImportHelper.hxx b/xmloff/inc/XMLEventImportHelper.hxx
index 0ad45da644ca..99d03999ec25 100644
--- a/xmloff/inc/XMLEventImportHelper.hxx
+++ b/xmloff/inc/XMLEventImportHelper.hxx
@@ -25,6 +25,7 @@
 
 #include <map>
 #include <vector>
+#include <memory>
 
 
 namespace com { namespace sun { namespace star {
@@ -57,10 +58,10 @@ class XMLEventImportHelper
     FactoryMap aFactoryMap;
 
     /// map from XML to API names
-    NameMap* pEventNameMap;
+    std::unique_ptr<NameMap> pEventNameMap;
 
     /// stack of previous aEventNameMap
-    std::vector< NameMap* > aEventNameMapVector;
+    std::vector< std::unique_ptr<NameMap> > aEventNameMapVector;
 
 public:
     XMLEventImportHelper();
diff --git a/xmloff/source/script/XMLEventImportHelper.cxx b/xmloff/source/script/XMLEventImportHelper.cxx
index 84bcd8eb1d16..0e45525856af 100644
--- a/xmloff/source/script/XMLEventImportHelper.cxx
+++ b/xmloff/source/script/XMLEventImportHelper.cxx
@@ -50,7 +50,7 @@ XMLEventImportHelper::~XMLEventImportHelper()
     aFactoryMap.clear();
 
     // delete name map
-    delete pEventNameMap;
+    pEventNameMap.reset();
 }
 
 void XMLEventImportHelper::RegisterFactory(
@@ -91,8 +91,8 @@ void XMLEventImportHelper::AddTranslationTable(
 void XMLEventImportHelper::PushTranslationTable()
 {
     // save old map and install new one
-    aEventNameMapVector.push_back(pEventNameMap);
-    pEventNameMap = new NameMap;
+    aEventNameMapVector.push_back(std::move(pEventNameMap));
+    pEventNameMap.reset( new NameMap );
 }
 
 void XMLEventImportHelper::PopTranslationTable()
@@ -102,8 +102,7 @@ void XMLEventImportHelper::PopTranslationTable()
     if ( !aEventNameMapVector.empty() )
     {
         // delete current and install old map
-        delete pEventNameMap;
-        pEventNameMap = aEventNameMapVector.back();
+        pEventNameMap = std::move(aEventNameMapVector.back());
         aEventNameMapVector.pop_back();
     }
 }


More information about the Libreoffice-commits mailing list