Return reference from Get_New_Partition() (#757671)
Return newly constructed partition object by reference rather than by copy from the Copy, Resize/Move and New dialog classes. This is another case of stopping copying partition objects in preparation for using polymorphic Partition objects. In C++ polymorphism has to use pass by pointer and reference and not pass by value, copying, to avoid object slicing. The returned reference to the partition is only valid until the dialog object containing the new_partition member is destroyed. This is okay because in all three cases the returned referenced partition is copied into a context with new lifetime expectations before the dialog object is destroyed. Case 1: GParted_Core::activate_paste() Referenced new_partition is copied in the OperationCopy constructor before the dialog object goes out of scope. Operation * operation = new OperationCopy( ..., dialog.Get_New_Partition( ... ), ... ); Case 2: GParted_Core::activate_new() Referenced new_partition is copied in the OperationCreate constructor before the dialog object goes out of scope. Operation * operation = new OperationCreate( ..., dialog.Get_New_Partition( ... ) ); Case 3: GParted_Core::activate_resize() Temporary partition object is copied from the referenced new_partition before the dialog object goes out of scope. Partition part_temp = dialog.Get_New_Partition( ... ); Bug 757671 - Rework Dialog_Partition_New::Get_New_Partition() a bit
parent
762cd109
Please register or sign in to comment