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 /vcl | |
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>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/unx/generic/printer/ppdparser.cxx | 33 |
1 files changed, 14 insertions, 19 deletions
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; } |