[gparted] Stop copying selected partition object in Information dialog (#750168)



commit efaea943014827cbda43412fb6c2081b4491ef19
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sun May 24 11:23:06 2015 +0100

    Stop copying selected partition object in Information dialog (#750168)
    
    When opening the Partition Information dialog, creation of the dialog
    object was creating a copy of the partition object to be displayed.  If
    this was an extended partition it also included recursively constructing
    the contained logical partitions too.
    
    Instead, replace the partition object in the Dialog_Partition_Info class
    with a reference to it.
    
    NOTE:
    In C++ a reference is really just a pointer under the hood.  As such,
    dereferences of a pointer to an object in the context of needing a
    reference to the object doesn't copy the object.  It merely initialises
    the reference from the pointer.
    
    Specifically, with this prototype:
        Dialog_Partition_Info( const Partition & partition );
    and the dialog object being constructed in Win_GParted::activate_info():
        Dialog_Partition_Info dialog( *selected_partition_ptr );
    the partition object is not copy constructed.  A reference (pointer) to
    it is merely passed to the dialog constructor.
    
    Bug 750168 - Reduce the amount of copying of partition objects

 include/Dialog_Partition_Info.h |    2 +-
 src/Dialog_Partition_Info.cc    |    4 +---
 2 files changed, 2 insertions(+), 4 deletions(-)
---
diff --git a/include/Dialog_Partition_Info.h b/include/Dialog_Partition_Info.h
index 245446b..66e4850 100644
--- a/include/Dialog_Partition_Info.h
+++ b/include/Dialog_Partition_Info.h
@@ -49,7 +49,7 @@ private:
        void drawingarea_on_realize();
        bool drawingarea_on_expose( GdkEventExpose *ev );
 
-       Partition partition ;
+       const Partition & partition;  // (Alias to element in Win_GParted::display_partitions[] vector).
 
        Gtk::HBox *hbox ;
        Gtk::DrawingArea drawingarea ;
diff --git a/src/Dialog_Partition_Info.cc b/src/Dialog_Partition_Info.cc
index f76c5f2..adeb21d 100644
--- a/src/Dialog_Partition_Info.cc
+++ b/src/Dialog_Partition_Info.cc
@@ -25,10 +25,8 @@
 namespace GParted
 {
 
-Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition )
+Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition ) : partition( partition )
 {
-       this ->partition = partition ;
-
        this ->set_has_separator( false ) ;
        //Set minimum dialog height so it fits on an 800x600 screen without
        //  too much whitespace (~500 px max for GNOME desktop).


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