Move vector of partition objects to a Win_GParted class member (#750168)

Win_GParted::Refresh_Visual() used a local variable containing a copy of
the vector of partitions in the current device to be displayed.  After
visually applying pending operations it loaded copies of each partition
object into the GUI widgets to display the disk graphic and partition
list, DrawingAreaVisualDisk and TreeView_Details classes respectively.
When a partition is selected in the UI, again a partition object is
copied.  Also several of the partition dialogs, including the
information dialog, take a copy of the partition object.  All these are
copies of the same set of partition objects, those currently being
displayed in the UI.

Move the vector of displayed partitions from a local variable in
Refresh_Visual() to a Win_GParted member variable.  This will allow for
the above cases to be changed to used pointers and references to the
same set of partition objects.

The valid lifetime of pointers to elements in this partition object
vector is from one refresh to the next, when the vector is cleared and
repopulated with a new set of partition objects.  This is exactly what
is needed as the GUI widgets are reloaded on each refresh, the selected
partition is reset and none of the partition dialog objects exist.
Dialog objects being created and destroyed on each use.

On the other hand some copies of partition objects currently being
displayed, still need to be made because they have lifetimes which need
to last longer than the next call to Refresh_Visual().  Specifically the
source of the copy partition and the partition objects copied into the
in the list of pending operations.

Bug 750168 - Reduce the amount of copying of partition objects
This commit is contained in:
Mike Fleetwood 2015-05-15 15:51:26 +01:00 committed by Curtis Gedak
parent 7090866b2a
commit 545b75d957
2 changed files with 21 additions and 19 deletions

View File

@ -183,6 +183,8 @@ private:
//private variables
unsigned int current_device ;
std::vector<Partition> display_partitions; // Copy of current device's partitions with any pending
// operations applied, as currently being shown in the GUI.
Partition selected_partition, copied_partition;
std::vector<Device> devices;
std::vector<Operation *> operations;

View File

@ -818,12 +818,12 @@ bool Win_GParted::Merge_Operations( unsigned int first, unsigned int second )
void Win_GParted::Refresh_Visual()
{
std::vector<Partition> partitions = devices[ current_device ] .partitions ;
display_partitions = devices[current_device].partitions;
//make all operations visible
for ( unsigned int t = 0 ; t < operations .size(); t++ )
if ( operations[ t ] ->device == devices[ current_device ] )
operations[ t ] ->apply_to_visual( partitions ) ;
operations[t]->apply_to_visual( display_partitions );
hbox_operations .load_operations( operations ) ;
@ -850,12 +850,12 @@ void Win_GParted::Refresh_Visual()
Sector largest_unalloc_size = -1 ;
Sector current_size ;
for ( unsigned int t = 0 ; t < partitions .size() ; t++ )
for ( unsigned int t = 0 ; t < display_partitions.size() ; t++ )
{
if ( partitions[ t ] .get_path() == copied_partition .get_path() )
copied_partition = partitions[ t ] ;
switch ( partitions[ t ] .type )
if ( display_partitions[t].get_path() == copied_partition.get_path() )
copied_partition = display_partitions[t];
switch ( display_partitions[t].type )
{
case TYPE_PRIMARY:
primary_count++;
@ -865,16 +865,16 @@ void Win_GParted::Refresh_Visual()
index_extended = t ;
primary_count++;
for ( unsigned int u = 0 ; u < partitions[ t ] .logicals .size() ; u ++ )
for ( unsigned int u = 0 ; u < display_partitions[t].logicals.size() ; u ++ )
{
switch ( partitions[ t ] .logicals[ u ] .type )
switch ( display_partitions[t].logicals[u].type )
{
case TYPE_UNALLOCATED:
current_size = partitions[ t ]. logicals[ u ] .get_sector_length() ;
current_size = display_partitions[t].logicals[u].get_sector_length();
if ( current_size > largest_unalloc_size )
{
largest_unalloc_size = current_size ;
selected_partition = partitions[ t ] .logicals[ u ] ;
selected_partition = display_partitions[t].logicals[u];
}
break;
@ -885,11 +885,11 @@ void Win_GParted::Refresh_Visual()
break;
case TYPE_UNALLOCATED:
current_size = partitions[ t ] .get_sector_length() ;
current_size = display_partitions[t].get_sector_length();
if ( current_size > largest_unalloc_size )
{
largest_unalloc_size = current_size ;
selected_partition = partitions[ t ] ;
selected_partition = display_partitions[t];
}
break;
@ -897,12 +897,12 @@ void Win_GParted::Refresh_Visual()
break;
}
}
//frame visualdisk
drawingarea_visualdisk .load_partitions( partitions, devices[ current_device ] .length ) ;
//treeview details
treeview_detail .load_partitions( partitions ) ;
// frame visualdisk
drawingarea_visualdisk.load_partitions( display_partitions, devices[current_device].length );
// treeview details
treeview_detail.load_partitions( display_partitions );
set_valid_operations() ;