From cc1448abd237291e1775aa88b67faa47890a5450 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sun, 17 May 2015 10:06:38 +0100 Subject: [PATCH] Store pointers to partition objects in DrawingAreaVisualDisk (#750168) This stops copying of each displayed partition object into the DrawingAreaVisualDisk class. Bug 750168 - Reduce the amount of copying of partition objects --- include/DrawingAreaVisualDisk.h | 6 +++--- src/DrawingAreaVisualDisk.cc | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/DrawingAreaVisualDisk.h b/include/DrawingAreaVisualDisk.h index d7c7ca2b..ccd1a156 100644 --- a/include/DrawingAreaVisualDisk.h +++ b/include/DrawingAreaVisualDisk.h @@ -83,9 +83,9 @@ private: Gdk::Color color ; Glib::RefPtr pango_layout; - //real partition - Partition partition ; - + // Pointer to real partition. (Alias to element in Win_GParted::display_partitions[] vector). + const Partition * partition_ptr; + std::vector logicals ; visual_partition() diff --git a/src/DrawingAreaVisualDisk.cc b/src/DrawingAreaVisualDisk.cc index 6be86f4b..65d0c5df 100644 --- a/src/DrawingAreaVisualDisk.cc +++ b/src/DrawingAreaVisualDisk.cc @@ -92,7 +92,7 @@ void DrawingAreaVisualDisk::set_static_data( const std::vector & part { visual_partitions .push_back( visual_partition() ) ; - visual_partitions .back() .partition = partitions[ t ] ; + visual_partitions.back().partition_ptr = & partitions[t]; Sector partition_length = partitions[ t ] .get_sector_length() ; visual_partitions .back() .fraction = partition_length / static_cast( length ) ; @@ -152,12 +152,12 @@ void DrawingAreaVisualDisk::calc_usage( std::vector & visual_p { for ( unsigned int t = 0 ; t < visual_partitions .size() ; t++ ) { - if ( visual_partitions[ t ] .partition .type != GParted::TYPE_UNALLOCATED && - visual_partitions[ t ] .partition .type != GParted::TYPE_EXTENDED ) + if ( visual_partitions[t].partition_ptr->type != TYPE_UNALLOCATED && + visual_partitions[t].partition_ptr->type != TYPE_EXTENDED ) { - if ( visual_partitions[ t ] .partition .sector_usage_known() ) + if ( visual_partitions[t].partition_ptr->sector_usage_known() ) { - visual_partitions[ t ] .partition .get_usage_triple( + visual_partitions[t].partition_ptr->get_usage_triple( visual_partitions[ t ] .length - BORDER *2, visual_partitions[ t ] .used_length, visual_partitions[ t ] .unused_length, @@ -314,7 +314,7 @@ void DrawingAreaVisualDisk::set_selected( const std::vector & if ( visual_partitions[ t ] .logicals .size() > 0 ) set_selected( visual_partitions[t].logicals, partition_ptr ); - if ( ! selected_vp && visual_partitions[t].partition == *partition_ptr ) + if ( ! selected_vp && *visual_partitions[t].partition_ptr == *partition_ptr ) selected_vp = & visual_partitions[ t ] ; } } @@ -361,7 +361,7 @@ bool DrawingAreaVisualDisk::on_button_press_event( GdkEventButton * event ) if ( selected_vp ) { - signal_partition_selected.emit( & selected_vp->partition, false ); + signal_partition_selected.emit( selected_vp->partition_ptr, false ); if ( event ->type == GDK_2BUTTON_PRESS ) signal_partition_activated .emit() ;