[gparted] Shallow copy Device object into Operation object (#750168)



commit 90e3ed68fc60c1395c2f3c20ed0b4493037753fb
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sun May 24 14:13:37 2015 +0100

    Shallow copy Device object into Operation object (#750168)
    
    When Operation objects are created they take a copy of the Device object
    to which the operation is to be applied.  The Device object includes a
    vector of all the contained Partition objects currently on the device,
    so these get copied too.
    
    These additional deep copied Partition objects in the Operation object
    are never accessed.  Therefore don't copy the contained Partition
    objects when copying the Device object into the Operation object.
    
    Bug 750168 - Reduce the amount of copying of partition objects

 include/Device.h                |    1 +
 src/Device.cc                   |   21 ++++++++++++++++++++-
 src/OperationChangeUUID.cc      |    2 +-
 src/OperationCheck.cc           |    2 +-
 src/OperationCopy.cc            |    2 +-
 src/OperationCreate.cc          |    2 +-
 src/OperationDelete.cc          |    2 +-
 src/OperationFormat.cc          |    2 +-
 src/OperationLabelFileSystem.cc |    2 +-
 src/OperationNamePartition.cc   |    2 +-
 src/OperationResizeMove.cc      |    3 ++-
 11 files changed, 31 insertions(+), 10 deletions(-)
---
diff --git a/include/Device.h b/include/Device.h
index 233923e..3184058 100644
--- a/include/Device.h
+++ b/include/Device.h
@@ -30,6 +30,7 @@ public:
        Device() ;
        ~Device() ;
 
+       Device get_copy_without_partitions() const;
        void add_path( const Glib::ustring & path, bool clear_paths = false ) ;
        void add_paths( const std::vector<Glib::ustring> & paths, bool clear_paths = false ) ;
        Glib::ustring get_path() const ;
diff --git a/src/Device.cc b/src/Device.cc
index 9ce6e3c..933aa16 100644
--- a/src/Device.cc
+++ b/src/Device.cc
@@ -36,7 +36,26 @@ void Device::Reset()
        readonly = false ;      
        max_partition_name_length = 0;
 }
-       
+
+Device Device::get_copy_without_partitions() const
+{
+       Device new_device;                                    // (1) Construct new Device object.
+       new_device.length                    = this->length;  // (2) Copy all members except partitions.
+       new_device.heads                     = this->heads;
+       new_device.sectors                   = this->sectors;
+       new_device.cylinders                 = this->cylinders;
+       new_device.cylsize                   = this->cylsize;
+       new_device.model                     = this->model;
+       new_device.disktype                  = this->disktype;
+       new_device.sector_size               = this->sector_size;
+       new_device.max_prims                 = this->max_prims;
+       new_device.highest_busy              = this->highest_busy;
+       new_device.readonly                  = this->readonly;
+       new_device.paths                     = this->paths;
+       new_device.max_partition_name_length = this->max_partition_name_length;
+       return new_device;                                    // (3) Return by value.
+}
+
 void Device::add_path( const Glib::ustring & path, bool clear_paths )
 {
        if ( clear_paths )
diff --git a/src/OperationChangeUUID.cc b/src/OperationChangeUUID.cc
index 0f0cc08..71e4577 100644
--- a/src/OperationChangeUUID.cc
+++ b/src/OperationChangeUUID.cc
@@ -26,7 +26,7 @@ OperationChangeUUID::OperationChangeUUID( const Device & device
 {
        type = OPERATION_CHANGE_UUID ;
 
-       this ->device = device ;
+       this->device = device.get_copy_without_partitions();
        this ->partition_original = partition_orig ;
        this ->partition_new = partition_new ;
 }
diff --git a/src/OperationCheck.cc b/src/OperationCheck.cc
index d6c97f0..80c3cc6 100644
--- a/src/OperationCheck.cc
+++ b/src/OperationCheck.cc
@@ -23,7 +23,7 @@ OperationCheck::OperationCheck( const Device & device, const Partition & partiti
 {
        type = OPERATION_CHECK ;
 
-       this ->device = device ;
+       this->device = device.get_copy_without_partitions();
        partition_original = partition ;
 }
        
diff --git a/src/OperationCopy.cc b/src/OperationCopy.cc
index afc3fe6..7b530e3 100644
--- a/src/OperationCopy.cc
+++ b/src/OperationCopy.cc
@@ -27,7 +27,7 @@ OperationCopy::OperationCopy( const Device & device,
 {
        type = OPERATION_COPY ;
 
-       this ->device = device ;
+       this->device = device.get_copy_without_partitions();
        this ->partition_original = partition_orig ;
        this ->partition_new = partition_new ;
        this ->partition_copied = partition_copied ;
diff --git a/src/OperationCreate.cc b/src/OperationCreate.cc
index 5271630..b561c00 100644
--- a/src/OperationCreate.cc
+++ b/src/OperationCreate.cc
@@ -26,7 +26,7 @@ OperationCreate::OperationCreate( const Device & device,
 {
        type = OPERATION_CREATE ;
 
-       this ->device = device ;
+       this->device = device.get_copy_without_partitions();
        this ->partition_original = partition_orig ;
        this ->partition_new = partition_new ;
 }
diff --git a/src/OperationDelete.cc b/src/OperationDelete.cc
index c6fbd14..2b293d1 100644
--- a/src/OperationDelete.cc
+++ b/src/OperationDelete.cc
@@ -24,7 +24,7 @@ OperationDelete::OperationDelete( const Device & device, const Partition & parti
 {
        type = OPERATION_DELETE ;
 
-       this ->device = device ;
+       this->device = device.get_copy_without_partitions();
        this ->partition_original = partition_orig ;
 }
        
diff --git a/src/OperationFormat.cc b/src/OperationFormat.cc
index a26807b..8dec4bd 100644
--- a/src/OperationFormat.cc
+++ b/src/OperationFormat.cc
@@ -25,7 +25,7 @@ OperationFormat::OperationFormat( const Device & device,
 {
        type = OPERATION_FORMAT ;
 
-       this ->device = device ;
+       this->device = device.get_copy_without_partitions();
        this ->partition_original = partition_orig ;
        this ->partition_new = partition_new ;
 }
diff --git a/src/OperationLabelFileSystem.cc b/src/OperationLabelFileSystem.cc
index 381602d..12d1015 100644
--- a/src/OperationLabelFileSystem.cc
+++ b/src/OperationLabelFileSystem.cc
@@ -25,7 +25,7 @@ OperationLabelFileSystem::OperationLabelFileSystem( const Device & device,
 {
        type = OPERATION_LABEL_FILESYSTEM;
 
-       this ->device = device ;
+       this->device = device.get_copy_without_partitions();
        this ->partition_original = partition_orig ;
        this ->partition_new = partition_new ;
 }
diff --git a/src/OperationNamePartition.cc b/src/OperationNamePartition.cc
index c206628..edda1ec 100644
--- a/src/OperationNamePartition.cc
+++ b/src/OperationNamePartition.cc
@@ -25,7 +25,7 @@ OperationNamePartition::OperationNamePartition( const Device & device,
 {
        type = OPERATION_NAME_PARTITION;
 
-       this->device = device;
+       this->device = device.get_copy_without_partitions();
        this->partition_original = partition_orig;
        this->partition_new = partition_new;
 }
diff --git a/src/OperationResizeMove.cc b/src/OperationResizeMove.cc
index 5741586..fe31312 100644
--- a/src/OperationResizeMove.cc
+++ b/src/OperationResizeMove.cc
@@ -25,7 +25,8 @@ OperationResizeMove::OperationResizeMove( const Device & device,
                                          const Partition & partition_new )
 {
        type = OPERATION_RESIZE_MOVE ;
-       this ->device = device ;
+
+       this->device = device.get_copy_without_partitions();
        this ->partition_original = partition_orig ;
        this ->partition_new = partition_new ;
 }


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