Kaydet (Commit) afe4d252 authored tarafından Noel Grandin's avatar Noel Grandin

use std::unique_ptr in PPDCache

Change-Id: Ib47ffaa0fe754d8aafdf338d8ec8c2109beb21a5
Reviewed-on: https://gerrit.libreoffice.org/43484Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst e355fb41
...@@ -177,7 +177,6 @@ private: ...@@ -177,7 +177,6 @@ private:
PPDParser( const OUString& rFile ); PPDParser( const OUString& rFile );
PPDParser( const OUString& rFile, std::vector<PPDKey*> keys ); PPDParser( const OUString& rFile, std::vector<PPDKey*> keys );
~PPDParser();
void parseOrderDependency(const OString& rLine); void parseOrderDependency(const OString& rLine);
void parseOpenUI(const OString& rLine, const OString& rPPDGroup); void parseOpenUI(const OString& rLine, const OString& rPPDGroup);
...@@ -190,6 +189,7 @@ private: ...@@ -190,6 +189,7 @@ private:
static void initPPDFiles(PPDCache &rPPDCache); static void initPPDFiles(PPDCache &rPPDCache);
static OUString getPPDFile( const OUString& rFile ); static OUString getPPDFile( const OUString& rFile );
public: public:
~PPDParser();
static const PPDParser* getParser( const OUString& rFile ); static const PPDParser* getParser( const OUString& rFile );
const PPDKey* getKey( int n ) const; const PPDKey* getKey( int n ) const;
......
...@@ -239,21 +239,11 @@ namespace psp ...@@ -239,21 +239,11 @@ namespace psp
class PPDCache class PPDCache
{ {
public: public:
std::list< PPDParser* > aAllParsers; std::list< std::unique_ptr<PPDParser> > aAllParsers;
std::unordered_map< OUString, OUString, OUStringHash >* pAllPPDFiles; std::unique_ptr<std::unordered_map< OUString, OUString, OUStringHash >> pAllPPDFiles;
PPDCache() PPDCache()
: pAllPPDFiles(nullptr) : 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) ...@@ -450,7 +440,7 @@ void PPDParser::initPPDFiles(PPDCache &rPPDCache)
if( rPPDCache.pAllPPDFiles ) if( rPPDCache.pAllPPDFiles )
return; return;
rPPDCache.pAllPPDFiles = new std::unordered_map< OUString, OUString, OUStringHash >; rPPDCache.pAllPPDFiles.reset(new std::unordered_map< OUString, OUString, OUStringHash >);
// check installation directories // check installation directories
std::vector< OUString > aPathList; std::vector< OUString > aPathList;
...@@ -509,7 +499,7 @@ OUString PPDParser::getPPDFile( const OUString& rFile ) ...@@ -509,7 +499,7 @@ OUString PPDParser::getPPDFile( const OUString& rFile )
if( it == rPPDCache.pAllPPDFiles->end() && bRetry ) if( it == rPPDCache.pAllPPDFiles->end() && bRetry )
{ {
// a new file ? rehash // a new file ? rehash
delete rPPDCache.pAllPPDFiles; rPPDCache.pAllPPDFiles = nullptr; rPPDCache.pAllPPDFiles.reset();
bRetry = false; bRetry = false;
// note this is optimized for office start where // note this is optimized for office start where
// no new files occur and initPPDFiles is called only once // no new files occur and initPPDFiles is called only once
...@@ -561,9 +551,9 @@ const PPDParser* PPDParser::getParser( const OUString& rFile ) ...@@ -561,9 +551,9 @@ const PPDParser* PPDParser::getParser( const OUString& rFile )
PPDCache &rPPDCache = thePPDCache::get(); PPDCache &rPPDCache = thePPDCache::get();
for( ::std::list< PPDParser* >::const_iterator it = rPPDCache.aAllParsers.begin(); it != rPPDCache.aAllParsers.end(); ++it ) for( auto const & i : rPPDCache.aAllParsers )
if( (*it)->m_aFile == aFile ) if( i->m_aFile == aFile )
return *it; return i.get();
PPDParser* pNewParser = nullptr; PPDParser* pNewParser = nullptr;
if( !aFile.startsWith( "CUPS:" ) && !aFile.startsWith( "CPD:" ) ) if( !aFile.startsWith( "CUPS:" ) && !aFile.startsWith( "CPD:" ) )
...@@ -587,9 +577,14 @@ const PPDParser* PPDParser::getParser( const OUString& rFile ) ...@@ -587,9 +577,14 @@ const PPDParser* PPDParser::getParser( const OUString& rFile )
{ {
// this may actually be the SGENPRT parser, // this may actually be the SGENPRT parser,
// so ensure uniqueness here // 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 // insert new parser to list
rPPDCache.aAllParsers.push_front( pNewParser ); rPPDCache.aAllParsers.push_front( std::unique_ptr<PPDParser>(pNewParser) );
} }
return pNewParser; return pNewParser;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment