[Libreoffice-commits] core.git: include/vcl vcl/unx

Noel Grandin noel.grandin at collabora.co.uk
Wed Oct 18 10:25:11 UTC 2017


 include/vcl/ppdparser.hxx             |    2 +-
 vcl/unx/generic/printer/ppdparser.cxx |   33 ++++++++++++++-------------------
 2 files changed, 15 insertions(+), 20 deletions(-)

New commits:
commit afe4d2527ec72e7493a2b1431559652ef45bebab
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Oct 18 09:43:21 2017 +0200

    use std::unique_ptr in PPDCache
    
    Change-Id: Ib47ffaa0fe754d8aafdf338d8ec8c2109beb21a5
    Reviewed-on: https://gerrit.libreoffice.org/43484
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/vcl/ppdparser.hxx b/include/vcl/ppdparser.hxx
index 16f93e080e76..d01852117b0a 100644
--- a/include/vcl/ppdparser.hxx
+++ b/include/vcl/ppdparser.hxx
@@ -177,7 +177,6 @@ private:
 
     PPDParser( const OUString& rFile );
     PPDParser( const OUString& rFile, std::vector<PPDKey*> keys );
-    ~PPDParser();
 
     void parseOrderDependency(const OString& rLine);
     void parseOpenUI(const OString& rLine, const OString& rPPDGroup);
@@ -190,6 +189,7 @@ private:
     static void initPPDFiles(PPDCache &rPPDCache);
     static OUString getPPDFile( const OUString& rFile );
 public:
+    ~PPDParser();
     static const PPDParser* getParser( const OUString& rFile );
 
     const PPDKey*   getKey( int n ) const;
diff --git a/vcl/unx/generic/printer/ppdparser.cxx b/vcl/unx/generic/printer/ppdparser.cxx
index 60df9da4b33e..3c7e3555cdb8 100644
--- a/vcl/unx/generic/printer/ppdparser.cxx
+++ b/vcl/unx/generic/printer/ppdparser.cxx
@@ -239,21 +239,11 @@ namespace psp
     class PPDCache
     {
     public:
-        std::list< PPDParser* > aAllParsers;
-        std::unordered_map< OUString, OUString, OUStringHash >* pAllPPDFiles;
+        std::list< std::unique_ptr<PPDParser> > aAllParsers;
+        std::unique_ptr<std::unordered_map< OUString, OUString, OUStringHash >> pAllPPDFiles;
         PPDCache()
             : pAllPPDFiles(nullptr)
         {}
-        ~PPDCache()
-        {
-            while( aAllParsers.begin() != aAllParsers.end() )
-            {
-                delete aAllParsers.front();
-                aAllParsers.pop_front();
-            }
-            delete pAllPPDFiles;
-            pAllPPDFiles = nullptr;
-        }
     };
 }
 
@@ -450,7 +440,7 @@ void PPDParser::initPPDFiles(PPDCache &rPPDCache)
     if( rPPDCache.pAllPPDFiles )
         return;
 
-    rPPDCache.pAllPPDFiles = new std::unordered_map< OUString, OUString, OUStringHash >;
+    rPPDCache.pAllPPDFiles.reset(new std::unordered_map< OUString, OUString, OUStringHash >);
 
     // check installation directories
     std::vector< OUString > aPathList;
@@ -509,7 +499,7 @@ OUString PPDParser::getPPDFile( const OUString& rFile )
             if( it == rPPDCache.pAllPPDFiles->end() && bRetry )
             {
                 // a new file ? rehash
-                delete rPPDCache.pAllPPDFiles; rPPDCache.pAllPPDFiles = nullptr;
+                rPPDCache.pAllPPDFiles.reset();
                 bRetry = false;
                 // note this is optimized for office start where
                 // no new files occur and initPPDFiles is called only once
@@ -561,9 +551,9 @@ const PPDParser* PPDParser::getParser( const OUString& rFile )
 
 
     PPDCache &rPPDCache = thePPDCache::get();
-    for( ::std::list< PPDParser* >::const_iterator it = rPPDCache.aAllParsers.begin(); it != rPPDCache.aAllParsers.end(); ++it )
-        if( (*it)->m_aFile == aFile )
-            return *it;
+    for( auto const & i : rPPDCache.aAllParsers )
+        if( i->m_aFile == aFile )
+            return i.get();
 
     PPDParser* pNewParser = nullptr;
     if( !aFile.startsWith( "CUPS:" ) && !aFile.startsWith( "CPD:" ) )
@@ -587,9 +577,14 @@ const PPDParser* PPDParser::getParser( const OUString& rFile )
     {
         // this may actually be the SGENPRT parser,
         // so ensure uniqueness here
-        rPPDCache.aAllParsers.remove( pNewParser );
+        rPPDCache.aAllParsers.erase(
+                std::remove_if(
+                    rPPDCache.aAllParsers.begin(),
+                    rPPDCache.aAllParsers.end(),
+                    [pNewParser] (std::unique_ptr<PPDParser> const & x) { return x.get() == pNewParser; } ),
+                rPPDCache.aAllParsers.end());
         // insert new parser to list
-        rPPDCache.aAllParsers.push_front( pNewParser );
+        rPPDCache.aAllParsers.push_front( std::unique_ptr<PPDParser>(pNewParser) );
     }
     return pNewParser;
 }


More information about the Libreoffice-commits mailing list