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

Julien Nabet serval2412 at yahoo.fr
Fri Oct 20 04:14:59 UTC 2017


 vcl/inc/printerinfomanager.hxx                 |    4 ++--
 vcl/unx/generic/printer/printerinfomanager.cxx |   22 +++++++++++-----------
 2 files changed, 13 insertions(+), 13 deletions(-)

New commits:
commit c16804de78b1cf1ad906eaacbcc7c51d35218d8a
Author: Julien Nabet <serval2412 at yahoo.fr>
Date:   Wed Oct 18 22:39:33 2017 +0200

    Replace list by unordered_set for m_aAlternateFiles (vcl)
    
    Change-Id: I66ea61972fed87245b33dfe355eff58d23041120
    Reviewed-on: https://gerrit.libreoffice.org/43520
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Julien Nabet <serval2412 at yahoo.fr>

diff --git a/vcl/inc/printerinfomanager.hxx b/vcl/inc/printerinfomanager.hxx
index 3fe420150cea..315d7253ae8b 100644
--- a/vcl/inc/printerinfomanager.hxx
+++ b/vcl/inc/printerinfomanager.hxx
@@ -21,9 +21,9 @@
 #define INCLUDED_VCL_PRINTERINFOMANAGER_HXX
 
 #include <memory>
-#include <list>
 #include <vector>
 #include <unordered_map>
+#include <unordered_set>
 
 #include <vcl/dllapi.h>
 #include <vcl/jobdata.hxx>
@@ -90,7 +90,7 @@ protected:
         OUString         m_aFile;
         // details other config files that have this printer
         // in case of removal all have to be removed
-        std::list< OUString > m_aAlternateFiles;
+        std::unordered_set< OUString, OUStringHash > m_aAlternateFiles;
         // group in m_aFile containing the printer
         // this must be unique over all configuration files
         // it usually should be the printer name
diff --git a/vcl/unx/generic/printer/printerinfomanager.cxx b/vcl/unx/generic/printer/printerinfomanager.cxx
index 842f11deea22..ac5779a6ae57 100644
--- a/vcl/unx/generic/printer/printerinfomanager.cxx
+++ b/vcl/unx/generic/printer/printerinfomanager.cxx
@@ -463,7 +463,7 @@ void PrinterInfoManager::initialize()
                 if( find_it != m_aPrinters.end() )
                 {
                     aPrinter.m_aAlternateFiles = find_it->second.m_aAlternateFiles;
-                    aPrinter.m_aAlternateFiles.push_front( find_it->second.m_aFile );
+                    aPrinter.m_aAlternateFiles.emplace( find_it->second.m_aFile );
                 }
                 m_aPrinters[ aPrinterName ] = aPrinter;
             }
@@ -627,10 +627,9 @@ bool PrinterInfoManager::writePrinterConfig()
                 {
                     rofiles[ it->second.m_aFile ] = 1;
                     // update alternate file list
-                    // the remove operation ensures uniqueness of each alternate
-                    it->second.m_aAlternateFiles.remove( it->second.m_aFile );
-                    it->second.m_aAlternateFiles.remove( files.begin()->first );
-                    it->second.m_aAlternateFiles.push_front( it->second.m_aFile );
+                    // be sure m_aAlternateFiles doesn't contain the m_aFile value
+                    it->second.m_aAlternateFiles.erase( files.begin()->first );
+                    it->second.m_aAlternateFiles.emplace( it->second.m_aFile );
                     // update file
                     it->second.m_aFile = files.begin()->first;
                 }
@@ -770,11 +769,13 @@ bool PrinterInfoManager::removePrinter( const OUString& rPrinterName, bool bChec
                 bSuccess = false;
             else
             {
-                for( std::list< OUString >::const_iterator file_it = it->second.m_aAlternateFiles.begin();
-                file_it != it->second.m_aAlternateFiles.end() && bSuccess; ++file_it )
+                for (auto const& file : it->second.m_aAlternateFiles)
                 {
-                    if( ! checkWriteability( *file_it ) )
+                    if( ! checkWriteability(file) )
+                    {
                         bSuccess = false;
+                        break;
+                    }
                 }
             }
             if( bSuccess && ! bCheckOnly )
@@ -783,10 +784,9 @@ bool PrinterInfoManager::removePrinter( const OUString& rPrinterName, bool bChec
                 Config aConfig( it->second.m_aFile );
                 aConfig.DeleteGroup( it->second.m_aGroup );
                 aConfig.Flush();
-                for( std::list< OUString >::const_iterator file_it = it->second.m_aAlternateFiles.begin();
-                file_it != it->second.m_aAlternateFiles.end() && bSuccess; ++file_it )
+                for (auto const& file : it->second.m_aAlternateFiles)
                 {
-                    Config aAltConfig( *file_it );
+                    Config aAltConfig( file );
                     aAltConfig.DeleteGroup( it->second.m_aGroup );
                     aAltConfig.Flush();
                 }


More information about the Libreoffice-commits mailing list