[gparted] Return and use constant reference from Partition::get_filesystem_label() (!94)



commit c8f640655c56a4335bfd281650f7a92dd5780801
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Tue Nov 2 20:03:08 2021 +0000

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

 include/Partition.h    | 2 +-
 src/Partition.cc       | 8 ++++++--
 src/TreeView_Detail.cc | 2 +-
 src/udf.cc             | 2 +-
 4 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/include/Partition.h b/include/Partition.h
index 72a9d7ce..26a11df4 100644
--- a/include/Partition.h
+++ b/include/Partition.h
@@ -119,7 +119,7 @@ public:
        Sector get_sector() const ;
        bool test_overlap( const Partition & partition ) const ;
        bool filesystem_label_known() const;
-       Glib::ustring get_filesystem_label() const;
+       const Glib::ustring& get_filesystem_label() const;
        void set_filesystem_label( const Glib::ustring & filesystem_label );
 
        // Message accessors.  Messages are stored locally and accessed globally.
diff --git a/src/Partition.cc b/src/Partition.cc
index dde1ffc8..bef26dd1 100644
--- a/src/Partition.cc
+++ b/src/Partition.cc
@@ -271,14 +271,18 @@ bool Partition::filesystem_label_known() const
        return have_filesystem_label;
 }
 
+
 //Return the file system label or "" if unknown.
-Glib::ustring Partition::get_filesystem_label() const
+const Glib::ustring& Partition::get_filesystem_label() const
 {
        if ( have_filesystem_label )
                return filesystem_label;
-       return "";
+
+       static Glib::ustring unknown_label;
+       return unknown_label;
 }
 
+
 void Partition::set_filesystem_label( const Glib::ustring & filesystem_label )
 {
        this->filesystem_label = filesystem_label;
diff --git a/src/TreeView_Detail.cc b/src/TreeView_Detail.cc
index aa2eacef..a63cd4eb 100644
--- a/src/TreeView_Detail.cc
+++ b/src/TreeView_Detail.cc
@@ -197,7 +197,7 @@ void TreeView_Detail::create_row( const Gtk::TreeRow & treerow,
                show_mountpoints = true;
 
        //label
-       Glib::ustring temp_filesystem_label = filesystem_ptn.get_filesystem_label();
+       const Glib::ustring& temp_filesystem_label = filesystem_ptn.get_filesystem_label();
        treerow[treeview_detail_columns.label] = temp_filesystem_label;
        if ( ! temp_filesystem_label.empty() )
                show_labels = true;
diff --git a/src/udf.cc b/src/udf.cc
index 48625ea0..839ebb69 100644
--- a/src/udf.cc
+++ b/src/udf.cc
@@ -200,7 +200,7 @@ bool udf::create( const Partition & new_partition, OperationDetail & operationde
        Glib::ustring label_args;
        if ( ! new_partition.get_filesystem_label().empty() )
        {
-               const Glib::ustring label = new_partition.get_filesystem_label();
+               const Glib::ustring& label = new_partition.get_filesystem_label();
 
                // Mkudffs from udftools prior to version 1.1 damages the label if it
                // contains non-ASCII characters.  Therefore do not allow a label with


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