Store pointers to partition objects in TreeView_Details (#750168)

This stops copying of each displayed partition object into the
TreeView_Details class.

It also stops copy constructing lots of partition objects when just
clicking on a partition in the disk graphic.  The disk graphic needs to
inform the main GUI and then the partition list which partition has been
selected.  The call sequence goes like:

    DrawingAreaVisualDisk::on_button_press_event(event)
      Win_GParted::on_partition_selected(partition_ptr, src_is_treeview)
        TreeView_Detail::set_selected(partition_ptr)
          TreeView_Detail::set_selected(rows, partition_ptr,
                                        inside_extended)

Relevant source and highlighted comparison line:

   140  bool TreeView_Detail::set_selected( Gtk::TreeModel::Children rows,
   141                                      const Partition * partition_ptr, bool inside_extended )
   142  {
   143          for ( unsigned int t = 0 ; t < rows .size() ; t++ )
   144          {
>> 145                  if ( static_cast<Partition>( rows[t][treeview_detail_columns.partition] ) == *partition_ptr )
   146                  {
   147                          if ( inside_extended )
   148                                  expand_all() ;
   149
   150                          set_cursor( static_cast<Gtk::TreePath>( rows[ t ] ) ) ;
   151                          return true ;
   152                  }
   153
   154                  if ( set_selected( rows[t].children(), partition_ptr, true ) )
   155                          return true ;
   156          }
   157
   158          return false ;
   159  }

Then in this function the partition selected in the disk graphic
(partition_ptr parameter) is compared in turn with each partition object
stored in the Gtk::TreeView model to find the matching one to mark it as
selected.  This mere act of accessing the partition object stored in a
row of the Gtk::TreeView model causes it to be copy constructed.  So
clicking on the 5th partition in the disk graphic will copy construct
the first 5 partition objects just to do a compare to find the matching
one.

This is because it is not possible to get a reference from a
Gtk:TreeViewProxy in gtkmm.  Merely accessing a value in a Gtk::TreeView
model takes a copy of that value.

    Subject: get a reference from a Gtk::TreeValueProxy
    http://comments.gmane.org/gmane.comp.gnome.gtkmm/2217
    http://marc.info/?t=104400417500001&r=1&w=4

Bug 750168 - Reduce the amount of copying of partition objects
This commit is contained in:
Mike Fleetwood 2015-05-16 22:36:29 +01:00 committed by Curtis Gedak
parent c430acf52a
commit acd5d7e580
2 changed files with 9 additions and 9 deletions

View File

@ -81,14 +81,15 @@ private:
Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > icon1 ;
Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > icon2 ;
Gtk::TreeModelColumn<Glib::ustring> flags;
Gtk::TreeModelColumn<Partition> partition; //hidden column
Gtk::TreeModelColumn<const Partition *> partition_ptr; // Hidden column. (Alias to element in
// Win_GParted::display_partitions[] vector).
treeview_detail_Columns()
{
add( path ); add( name ); add( filesystem ); add( mountpoint ); add( label );
add( size ); add( used ); add( unused ); add( color );
add( text_color ); add( mount_text_color ); add( icon1 );
add( icon2 ) ; add( flags ); add( partition );
add( icon2 ); add( flags ); add( partition_ptr );
}
};

View File

@ -142,7 +142,7 @@ bool TreeView_Detail::set_selected( Gtk::TreeModel::Children rows,
{
for ( unsigned int t = 0 ; t < rows .size() ; t++ )
{
if ( static_cast<Partition>( rows[t][treeview_detail_columns.partition] ) == *partition_ptr )
if ( * static_cast<const Partition *>( rows[t][treeview_detail_columns.partition_ptr] ) == *partition_ptr )
{
if ( inside_extended )
expand_all() ;
@ -212,8 +212,8 @@ void TreeView_Detail::create_row( const Gtk::TreeRow & treerow, const Partition
treerow[ treeview_detail_columns .flags ] =
Glib::build_path( ", ", partition .flags ) ;
//hidden column (partition object)
treerow[ treeview_detail_columns .partition ] = partition;
// Hidden column (pointer to partition object)
treerow[treeview_detail_columns.partition_ptr] = & partition;
}
bool TreeView_Detail::on_button_press_event( GdkEventButton * event )
@ -241,8 +241,7 @@ void TreeView_Detail::on_selection_changed()
if ( ! block && treeselection ->get_selected() != 0 )
{
Gtk::TreeRow row = static_cast<Gtk::TreeRow>( * treeselection ->get_selected() ) ;
Partition selected_partition = row[treeview_detail_columns.partition];
signal_partition_selected.emit( & selected_partition, true );
signal_partition_selected.emit( row[treeview_detail_columns.partition_ptr], true );
}
}