diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-18 09:43:21 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-18 12:24:46 +0200 |
commit | afe4d2527ec72e7493a2b1431559652ef45bebab (patch) | |
tree | e5eb2cc54f0cfc626f8a95fd3f2161df6797901c | |
parent | e355fb41db5fd199a0eb44e95c39ea7adfda49b8 (diff) |
use std::unique_ptr in PPDCache
Change-Id: Ib47ffaa0fe754d8aafdf338d8ec8c2109beb21a5
Reviewed-on: https://gerrit.libreoffice.org/43484
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/vcl/ppdparser.hxx | 2 | ||||
-rw-r--r-- | vcl/unx/generic/printer/ppdparser.cxx | 33 |
2 files changed, 15 insertions, 20 deletions
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; } |