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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Sep 26 06:58:53 UTC 2018


 i18npool/source/localedata/localedata.cxx     |   39 +++++++++-----------------
 svgio/inc/svgdocument.hxx                     |    6 +++-
 svgio/inc/svgnode.hxx                         |    2 -
 svgio/source/svgreader/svgdocument.cxx        |   12 ++------
 svgio/source/svgreader/svgdocumenthandler.cxx |    5 ++-
 svgio/source/svguno/xsvgparser.cxx            |    7 ----
 6 files changed, 26 insertions(+), 45 deletions(-)

New commits:
commit 6cc5c6dea2b03a14e051728aa513fb206929ea86
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Sep 25 13:23:48 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Sep 26 08:58:42 2018 +0200

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

diff --git a/svgio/inc/svgdocument.hxx b/svgio/inc/svgdocument.hxx
index de7fbc304c88..e414b19390db 100644
--- a/svgio/inc/svgdocument.hxx
+++ b/svgio/inc/svgdocument.hxx
@@ -21,12 +21,16 @@
 #define INCLUDED_SVGIO_INC_SVGDOCUMENT_HXX
 
 #include "svgnode.hxx"
+#include <memory>
 #include <unordered_map>
+#include <vector>
 
 namespace svgio
 {
     namespace svgreader
     {
+        typedef std::vector< std::unique_ptr<SvgNode> > SvgNodeVector;
+
         class SvgDocument
         {
         private:
@@ -52,7 +56,7 @@ namespace svgio
             SvgDocument& operator=(const SvgDocument&) = delete;
 
             /// append another root node, ownership changes
-            void appendNode(SvgNode* pNode);
+            void appendNode(std::unique_ptr<SvgNode> pNode);
 
             /// add/remove nodes with Id to mapper
             void addSvgNodeToMapper(const OUString& rStr, const SvgNode& rNode);
diff --git a/svgio/inc/svgnode.hxx b/svgio/inc/svgnode.hxx
index 2db5d490fa14..1f08f5fa5acf 100644
--- a/svgio/inc/svgnode.hxx
+++ b/svgio/inc/svgnode.hxx
@@ -45,8 +45,6 @@ namespace svgio
 {
     namespace svgreader
     {
-        typedef ::std::vector< SvgNode* > SvgNodeVector;
-
         enum XmlSpace
         {
             XmlSpace_notset,
diff --git a/svgio/source/svgreader/svgdocument.cxx b/svgio/source/svgreader/svgdocument.cxx
index 44fb0d507eec..716db822a83c 100644
--- a/svgio/source/svgreader/svgdocument.cxx
+++ b/svgio/source/svgreader/svgdocument.cxx
@@ -33,18 +33,12 @@ namespace svgio
 
         SvgDocument::~SvgDocument()
         {
-            while(!maNodes.empty())
-            {
-                SvgNode* pCandidate = maNodes[maNodes.size() - 1];
-                delete pCandidate;
-                maNodes.pop_back();
-            }
         }
 
-        void SvgDocument::appendNode(SvgNode* pNode)
+        void SvgDocument::appendNode(std::unique_ptr<SvgNode> pNode)
         {
-            OSL_ENSURE(pNode, "OOps, empty node added (!)");
-            maNodes.push_back(pNode);
+            assert(pNode);
+            maNodes.push_back(std::move(pNode));
         }
 
         void SvgDocument::addSvgNodeToMapper(const OUString& rStr, const SvgNode& rNode)
diff --git a/svgio/source/svgreader/svgdocumenthandler.cxx b/svgio/source/svgreader/svgdocumenthandler.cxx
index d8a36c99c073..447221b55215 100644
--- a/svgio/source/svgreader/svgdocumenthandler.cxx
+++ b/svgio/source/svgreader/svgdocumenthandler.cxx
@@ -153,7 +153,8 @@ namespace svgio
                     mpTarget = const_cast< SvgNode* >(mpTarget->getParent());
 
                 const SvgNodeVector& rOwnedTopLevels = maDocument.getSvgNodeVector();
-                if (std::find(rOwnedTopLevels.begin(), rOwnedTopLevels.end(), mpTarget) == rOwnedTopLevels.end())
+                if (std::none_of(rOwnedTopLevels.begin(), rOwnedTopLevels.end(),
+                                [&](std::unique_ptr<SvgNode> const & p) { return p.get() == mpTarget; }))
                     delete mpTarget;
             }
             OSL_ENSURE(!maCssContents.size(), "SvgDocHdl destructed with active css style stack entry (!)");
@@ -487,7 +488,7 @@ namespace svgio
                             if(!mpTarget->getParent())
                             {
                                 // last element closing, save this tree
-                                maDocument.appendNode(mpTarget);
+                                maDocument.appendNode(std::unique_ptr<SvgNode>(mpTarget));
                             }
 
                             mpTarget = const_cast< SvgNode* >(mpTarget->getParent());
diff --git a/svgio/source/svguno/xsvgparser.cxx b/svgio/source/svguno/xsvgparser.cxx
index 46ada4858a42..2f2a51c5c318 100644
--- a/svgio/source/svguno/xsvgparser.cxx
+++ b/svgio/source/svguno/xsvgparser.cxx
@@ -143,13 +143,8 @@ namespace svgio
                 }
 
                 // decompose to primitives
-                const SvgNodeVector& rResults = pSvgDocHdl->getSvgDocument().getSvgNodeVector();
-                const sal_uInt32 nCount(rResults.size());
-
-                for(sal_uInt32 a(0); a < nCount; a++)
+                for(std::unique_ptr<SvgNode> const & pCandidate : pSvgDocHdl->getSvgDocument().getSvgNodeVector())
                 {
-                    SvgNode* pCandidate = rResults[a];
-
                     if(Display_none != pCandidate->getDisplay())
                     {
                         pCandidate->decomposeSvgNode(aRetval, false);
commit 0699a18c622149ac6dbc898bf920c47c45ccd5b9
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Sep 25 13:23:34 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Sep 26 08:58:31 2018 +0200

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

diff --git a/i18npool/source/localedata/localedata.cxx b/i18npool/source/localedata/localedata.cxx
index 75427fae14cc..11258ab7d9c4 100644
--- a/i18npool/source/localedata/localedata.cxx
+++ b/i18npool/source/localedata/localedata.cxx
@@ -481,11 +481,11 @@ public:
 
     oslGenericFunction getFunctionSymbolByName(
             const OUString& localeName, const sal_Char* pFunction,
-            LocaleDataLookupTableItem** pOutCachedItem );
+            std::unique_ptr<LocaleDataLookupTableItem>* pOutCachedItem );
 
 private:
     ::osl::Mutex maMutex;
-    ::std::vector< LocaleDataLookupTableItem* >  maLookupTable;
+    ::std::vector< LocaleDataLookupTableItem >  maLookupTable;
 };
 
 // from instance.hxx: Helper base class for a late-initialized
@@ -502,20 +502,14 @@ lcl_LookupTableHelper::lcl_LookupTableHelper()
 
 lcl_LookupTableHelper::~lcl_LookupTableHelper()
 {
-    std::vector<LocaleDataLookupTableItem*>::const_iterator aEnd(maLookupTable.end());
-    std::vector<LocaleDataLookupTableItem*>::iterator aIter(maLookupTable.begin());
-
-    for ( ; aIter != aEnd; ++aIter ) {
-        LocaleDataLookupTableItem* pItem = *aIter;
-        delete pItem->module;
-        delete pItem;
+    for ( LocaleDataLookupTableItem& item : maLookupTable ) {
+        delete item.module;
     }
-    maLookupTable.clear();
 }
 
 oslGenericFunction lcl_LookupTableHelper::getFunctionSymbolByName(
         const OUString& localeName, const sal_Char* pFunction,
-        LocaleDataLookupTableItem** pOutCachedItem )
+        std::unique_ptr<LocaleDataLookupTableItem>* pOutCachedItem )
 {
     OUString aFallback;
     bool bFallback = (localeName.indexOf( cUnder) < 0);
@@ -540,14 +534,14 @@ oslGenericFunction lcl_LookupTableHelper::getFunctionSymbolByName(
                         strlen(i.pLocale) + 1 + strlen(pFunction)));
             {
                 ::osl::MutexGuard aGuard( maMutex );
-                for (LocaleDataLookupTableItem* pCurrent : maLookupTable)
+                for (LocaleDataLookupTableItem & rCurrent : maLookupTable)
                 {
-                    if (pCurrent->dllName == i.pLib)
+                    if (rCurrent.dllName == i.pLib)
                     {
                         OSL_ASSERT( pOutCachedItem );
                         if( pOutCachedItem )
                         {
-                            (*pOutCachedItem) = new LocaleDataLookupTableItem( *pCurrent );
+                            (*pOutCachedItem).reset(new LocaleDataLookupTableItem( rCurrent ));
                             (*pOutCachedItem)->localeName = i.pLocale;
                             return (*pOutCachedItem)->module->getFunctionSymbol(
                                     aBuf.appendAscii( pFunction).append( cUnder).
@@ -570,12 +564,11 @@ oslGenericFunction lcl_LookupTableHelper::getFunctionSymbolByName(
             if ( module->loadRelative(&thisModule, aBuf.makeStringAndClear()) )
             {
                 ::osl::MutexGuard aGuard( maMutex );
-                LocaleDataLookupTableItem* pNewItem = new LocaleDataLookupTableItem(i.pLib, module, i.pLocale);
-                maLookupTable.push_back(pNewItem);
+                maLookupTable.emplace_back(i.pLib, module, i.pLocale);
                 OSL_ASSERT( pOutCachedItem );
                 if( pOutCachedItem )
                 {
-                    (*pOutCachedItem) = new LocaleDataLookupTableItem( *pNewItem );
+                    pOutCachedItem->reset(new LocaleDataLookupTableItem( maLookupTable.back() ));
                     return module->getFunctionSymbol(
                             aBuf.appendAscii(pFunction).append(cUnder).
                             appendAscii((*pOutCachedItem)->localeName).makeStringAndClear());
@@ -1455,7 +1448,7 @@ oslGenericFunction LocaleDataImpl::getFunctionSymbol( const Locale& rLocale, con
     }
 
     oslGenericFunction pSymbol = nullptr;
-    LocaleDataLookupTableItem *pCachedItem = nullptr;
+    std::unique_ptr<LocaleDataLookupTableItem> pCachedItem;
 
     // Load function with name <func>_<lang>_<country> or <func>_<bcp47> and
     // fallbacks.
@@ -1482,7 +1475,7 @@ oslGenericFunction LocaleDataImpl::getFunctionSymbol( const Locale& rLocale, con
         throw RuntimeException();
 
     if (pCachedItem)
-        cachedItem.reset(pCachedItem);
+        cachedItem = std::move(pCachedItem);
     if (cachedItem.get())
         cachedItem->aLocale = rLocale;
 
@@ -1500,16 +1493,12 @@ LocaleDataImpl::getAllInstalledLocaleNames()
 
         // Check if the locale is really available and not just in the table,
         // don't allow fall backs.
-        LocaleDataLookupTableItem *pCachedItem = nullptr;
+        std::unique_ptr<LocaleDataLookupTableItem> pCachedItem;
         if (lcl_LookupTableStatic::get().getFunctionSymbolByName( name, "getLocaleItem", &pCachedItem )) {
             if( pCachedItem )
-                cachedItem.reset( pCachedItem );
+                cachedItem = std::move( pCachedItem );
             seq[nInstalled++] = LanguageTag::convertToLocale( name.replace( cUnder, cHyphen), false);
         }
-        else
-        {
-            delete pCachedItem;
-        }
     }
     if ( nInstalled < nbOfLocales )
         seq.realloc( nInstalled );          // reflect reality


More information about the Libreoffice-commits mailing list