[gparted] Initialise file system objects only once



commit 5f6656f267151b452cc95e036f8ad138a153d397
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sun Mar 23 23:09:07 2014 +0000

    Initialise file system objects only once
    
    The code used to unnecessarily destroy and re-create the file system
    objects on every scan for file system support tools.
    
    Instead only create the file system objects once and just call each
    object's get_filesystem_support() method on each rescan.

 include/GParted_Core.h |    1 +
 src/GParted_Core.cc    |   20 +++++++++-----------
 2 files changed, 10 insertions(+), 11 deletions(-)
---
diff --git a/include/GParted_Core.h b/include/GParted_Core.h
index b726990..aa13daf 100644
--- a/include/GParted_Core.h
+++ b/include/GParted_Core.h
@@ -38,6 +38,7 @@ public:
        GParted_Core() ;
        ~GParted_Core() ;
 
+       void init_filesystems() ;
        void find_supported_filesystems() ;
        void set_user_devices( const std::vector<Glib::ustring> & user_devices ) ;
        void set_devices( std::vector<Device> & devices ) ;
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index aee6dc0..a59aee2 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -80,21 +80,14 @@ GParted_Core::GParted_Core()
        std::cout << "======================" << std::endl ;
 
        //initialize file system list
+       init_filesystems() ;
+
+       //Determine file system support capabilities for the first time
        find_supported_filesystems() ;
 }
 
-void GParted_Core::find_supported_filesystems()
+void GParted_Core::init_filesystems()
 {
-       std::map< FILESYSTEM, FileSystem * >::iterator f ;
-
-       // TODO: determine whether it is safe to initialize this only once
-       for ( f = FILESYSTEM_MAP .begin() ; f != FILESYSTEM_MAP .end() ; f++ ) {
-               if ( f ->second )
-                       delete f ->second ;
-       }
-
-       FILESYSTEM_MAP .clear() ;
-
        FILESYSTEM_MAP[ FS_UNKNOWN ]         = NULL ;
        FILESYSTEM_MAP[ FS_CLEARED ]         = NULL ;
        FILESYSTEM_MAP[ FS_BTRFS ]           = new btrfs() ;
@@ -120,6 +113,11 @@ void GParted_Core::find_supported_filesystems()
        FILESYSTEM_MAP[ FS_LUKS ]            = NULL ;
        FILESYSTEM_MAP[ FS_LINUX_SWRAID ]    = NULL ;
        FILESYSTEM_MAP[ FS_LINUX_SWSUSPEND ] = NULL ;
+}
+
+void GParted_Core::find_supported_filesystems()
+{
+       std::map< FILESYSTEM, FileSystem * >::iterator f ;
 
        //Iteration of std::map is ordered according to operator< of the key.
        //  Hence the FILESYSTEMS vector is constructed in FILESYSTEM enum


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]