[gparted] Stop copying selected_partition back on itself in the copy dialog (#750168)



commit 8b96f8409f9fe1777a1283c11ca7c58c229be2df
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Tue May 26 21:52:04 2015 +0100

    Stop copying selected_partition back on itself in the copy dialog (#750168)
    
    The code goes like this:
    
        Dialog_Partition_Copy::Get_New_Partition()
            call Dialog_Base_Partition::Get_New_Partition()
                Update this->selected_partition with results from running
                the dialog.
                return this->selected_partition by value.
            Save value back to this->selected_partition.
            Update this->selected_partition some more.
            return this->selected_partition by value.
    
    So there is an unnecessary copy of the partition object returned from
    the base class Get_New_Partition() function back to the same variable in
    the derived copy class Get_New_Partition() function.
    
    Need to keep the base class Get_New_Partition() function as derived
    class Dialog_Partition_Resize_Move uses that implementation as it
    doesn't override it, and it's part of the interface.
    
    Avoid this unnecessary copy by moving base class Get_New_Partition()
    code into a new private function, called prepare_new_partition(), which
    doesn't return anything.  Then have Get_New_Partition() in both classes
    just return the required partition object.  Like this:
    
        Dialog_Base_Partition::Get_New_Partition()
            call prepare_new_partition()
            return this->selected_partition by value.
    
        Dialog_Partition_Copy::Get_New_Partition()
            call Dialog_Base_Partition::prepare_new_partition()
            Update this->selected_partition some more.
            return this->selected_partition by value.
    
    Bug 750168 - Reduce the amount of copying of partition objects

 include/Dialog_Base_Partition.h |    4 +++-
 src/Dialog_Base_Partition.cc    |   10 +++++++---
 src/Dialog_Partition_Copy.cc    |    4 ++--
 3 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/include/Dialog_Base_Partition.h b/include/Dialog_Base_Partition.h
index dca4d1a..f262443 100644
--- a/include/Dialog_Base_Partition.h
+++ b/include/Dialog_Base_Partition.h
@@ -55,7 +55,9 @@ protected:
                NEW             = 1,
                PASTE           = 2
        };
-       
+
+       void prepare_new_partition( Byte_Value sector_size );
+
        void Set_Confirm_Button( CONFIRMBUTTON button_type ) ;
        void Set_MinMax_Text( Sector min, Sector max ) ;
 
diff --git a/src/Dialog_Base_Partition.cc b/src/Dialog_Base_Partition.cc
index 37375b4..4f4f654 100644
--- a/src/Dialog_Base_Partition.cc
+++ b/src/Dialog_Base_Partition.cc
@@ -136,7 +136,13 @@ void Dialog_Base_Partition::Set_Resizer( bool extended )
        this ->show_all_children() ;
 }
 
-Partition Dialog_Base_Partition::Get_New_Partition( Byte_Value sector_size ) 
+Partition Dialog_Base_Partition::Get_New_Partition( Byte_Value sector_size )
+{
+       prepare_new_partition( sector_size );
+       return selected_partition;
+}
+
+void Dialog_Base_Partition::prepare_new_partition( Byte_Value sector_size )
 {
        //set sector size of new partition
        selected_partition .sector_size = sector_size;
@@ -221,8 +227,6 @@ Partition Dialog_Base_Partition::Get_New_Partition( Byte_Value sector_size )
        //if the original before value has not changed, then set indicator to keep start sector unchanged
        if ( ORIG_BEFORE == spinbutton_before .get_value_as_int() )
                selected_partition .strict_start = TRUE ;
-
-       return selected_partition ;
 }
 
 void Dialog_Base_Partition::Set_Confirm_Button( CONFIRMBUTTON button_type ) 
diff --git a/src/Dialog_Partition_Copy.cc b/src/Dialog_Partition_Copy.cc
index e3d4f53..7744f66 100644
--- a/src/Dialog_Partition_Copy.cc
+++ b/src/Dialog_Partition_Copy.cc
@@ -97,7 +97,7 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
                       , ceil( fs .MAX / double(MEBIBYTE) )
                       ) ;
 
-       //set global selected_partition (see Dialog_Base_Partition::Get_New_Partition )
+       // Set member variable used in Dialog_Base_Partition::prepare_new_partition()
        this ->selected_partition = copied_partition ;
        this ->selected_partition .device_path = selected_partition .device_path ;
        this ->selected_partition .inside_extended = selected_partition .inside_extended ;
@@ -118,7 +118,7 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
 Partition Dialog_Partition_Copy::Get_New_Partition( Byte_Value sector_size )
 {
        //first call baseclass to get the correct new partition
-       selected_partition = Dialog_Base_Partition::Get_New_Partition( sector_size ) ;
+       Dialog_Base_Partition::prepare_new_partition( sector_size );
 
        //set proper name and status for partition
        selected_partition .status = GParted::STAT_COPY ;


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