[gparted] Return and use constant reference from LVM2_PV_Info::get_vg_name() (!94)



commit c35422a70c2f4de34cadaaf07bb8cd754f4bafb4
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Tue Nov 2 21:18:16 2021 +0000

    Return and use constant reference from LVM2_PV_Info::get_vg_name() (!94)
    
    Closes !94 - Make more getter methods use return-by-constant-reference

 include/LVM2_PV_Info.h | 2 +-
 src/GParted_Core.cc    | 4 ++--
 src/LVM2_PV_Info.cc    | 3 ++-
 src/Win_GParted.cc     | 2 +-
 src/lvm2_pv.cc         | 2 +-
 5 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/include/LVM2_PV_Info.h b/include/LVM2_PV_Info.h
index 9a00c8ba..c15235ee 100644
--- a/include/LVM2_PV_Info.h
+++ b/include/LVM2_PV_Info.h
@@ -55,7 +55,7 @@ class LVM2_PV_Info
 public:
        static bool is_lvm2_pv_supported();
        static void clear_cache();
-       static Glib::ustring get_vg_name( const Glib::ustring & path );
+       static const Glib::ustring& get_vg_name(const Glib::ustring& path);
        static Byte_Value get_size_bytes( const Glib::ustring & path );
        static Byte_Value get_free_bytes( const Glib::ustring & path );
        static bool has_active_lvs( const Glib::ustring & path );
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 159bafae..4eca00e7 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -1463,7 +1463,7 @@ void GParted_Core::set_mountpoints( Partition & partition )
 
        if (partition.fstype == FS_LVM2_PV)
        {
-               Glib::ustring vgname = LVM2_PV_Info::get_vg_name( partition.get_path() );
+               const Glib::ustring& vgname = LVM2_PV_Info::get_vg_name(partition.get_path());
                if ( ! vgname.empty() )
                        partition.add_mountpoint( vgname );
        }
@@ -3694,7 +3694,7 @@ bool GParted_Core::filesystem_resize_disallowed( const Partition & partition )
        if (partition.fstype == FS_LVM2_PV)
        {
                //The LVM2 PV can't be resized when it's a member of an export VG
-               Glib::ustring vgname = LVM2_PV_Info::get_vg_name( partition.get_path() );
+               const Glib::ustring& vgname = LVM2_PV_Info::get_vg_name(partition.get_path());
                if ( vgname .empty() )
                        return false ;
                return LVM2_PV_Info::is_vg_exported( vgname );
diff --git a/src/LVM2_PV_Info.cc b/src/LVM2_PV_Info.cc
index fc926d1d..204901d2 100644
--- a/src/LVM2_PV_Info.cc
+++ b/src/LVM2_PV_Info.cc
@@ -87,7 +87,8 @@ void LVM2_PV_Info::clear_cache()
        lvm2_pv_info_cache_initialized = false;
 }
 
-Glib::ustring LVM2_PV_Info::get_vg_name( const Glib::ustring & path )
+
+const Glib::ustring& LVM2_PV_Info::get_vg_name(const Glib::ustring& path)
 {
        initialize_if_required() ;
        const LVM2_PV& pv = get_pv_cache_entry_by_name(path);
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index 674f66ad..1e354583 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -3597,7 +3597,7 @@ bool Win_GParted::remove_non_empty_lvm2_pv_dialog( const OperationType optype )
        tmp_msg += "\n\n" ;
        tmp_msg += _( "Do you want to continue to forcibly delete the Physical Volume?" ) ;
 
-       Glib::ustring vgname = LVM2_PV_Info::get_vg_name( selected_partition_ptr->get_path() );
+       const Glib::ustring& vgname = LVM2_PV_Info::get_vg_name(selected_partition_ptr->get_path());
        std::vector<Glib::ustring> members ;
        if ( ! vgname .empty() )
                members = LVM2_PV_Info::get_vg_members( vgname );
diff --git a/src/lvm2_pv.cc b/src/lvm2_pv.cc
index 05977787..5ace9402 100644
--- a/src/lvm2_pv.cc
+++ b/src/lvm2_pv.cc
@@ -121,7 +121,7 @@ bool lvm2_pv::check_repair( const Partition & partition, OperationDetail & opera
 
 bool lvm2_pv::remove( const Partition & partition, OperationDetail & operationdetail )
 {
-       Glib::ustring vgname = LVM2_PV_Info::get_vg_name( partition.get_path() );
+       const Glib::ustring& vgname = LVM2_PV_Info::get_vg_name(partition.get_path());
        Glib::ustring cmd ;
        if ( vgname .empty() )
                cmd = "lvm pvremove " + Glib::shell_quote( partition.get_path() );


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