[gparted] Return and use constant reference from SWRaid::get_array() (!94)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Return and use constant reference from SWRaid::get_array() (!94)
- Date: Tue, 16 Nov 2021 19:54:14 +0000 (UTC)
commit b38ee9c8ace6dc3d194867bbefad8c7d0e7508f3
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Sat Nov 6 13:55:21 2021 +0000
Return and use constant reference from SWRaid::get_array() (!94)
Have to use a second constant reference variable array_path_2 in
GParted_Core::set_mountpoints() because by design C++ does not implement
rebinding of references [1].
[1] why doesn't C++ allow rebinding a reference?
https://stackoverflow.com/questions/27037744/why-doesnt-c-allow-rebinding-a-reference
Closes !94 - Make more getter methods use return-by-constant-reference
include/SWRaid_Info.h | 2 +-
src/GParted_Core.cc | 10 +++++-----
src/SWRaid_Info.cc | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
---
diff --git a/include/SWRaid_Info.h b/include/SWRaid_Info.h
index b1a14a58..5433690d 100644
--- a/include/SWRaid_Info.h
+++ b/include/SWRaid_Info.h
@@ -59,7 +59,7 @@ public:
static bool is_member( const Glib::ustring & member_path );
static bool is_member_active( const Glib::ustring & member_path );
static FSType get_fstype(const Glib::ustring& member_path);
- static Glib::ustring get_array( const Glib::ustring & member_path );
+ static const Glib::ustring& get_array(const Glib::ustring& member_path);
static Glib::ustring get_uuid( const Glib::ustring & member_path );
static Glib::ustring get_label( const Glib::ustring & member_path );
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 4eca00e7..ece68950 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -1469,22 +1469,22 @@ void GParted_Core::set_mountpoints( Partition & partition )
}
else if (partition.fstype == FS_LINUX_SWRAID)
{
- Glib::ustring array_path = SWRaid_Info::get_array( partition.get_path() );
+ const Glib::ustring& array_path = SWRaid_Info::get_array(partition.get_path());
if ( ! array_path.empty() )
partition.add_mountpoint( array_path );
}
else if (partition.fstype == FS_ATARAID)
{
- Glib::ustring array_path = SWRaid_Info::get_array(partition.get_path());
+ const Glib::ustring& array_path = SWRaid_Info::get_array(partition.get_path());
if (! array_path.empty())
{
partition.add_mountpoint(array_path);
}
else
{
- array_path = dmraid.get_array(partition.get_path());
- if (! array_path.empty())
- partition.add_mountpoint(array_path);
+ const Glib::ustring& array_path_2 = dmraid.get_array(partition.get_path());
+ if (! array_path_2.empty())
+ partition.add_mountpoint(array_path_2);
}
}
else if (partition.fstype == FS_LUKS)
diff --git a/src/SWRaid_Info.cc b/src/SWRaid_Info.cc
index a719762d..217e9521 100644
--- a/src/SWRaid_Info.cc
+++ b/src/SWRaid_Info.cc
@@ -86,7 +86,7 @@ FSType SWRaid_Info::get_fstype(const Glib::ustring& member_path)
// Return array /dev entry (e.g. "/dev/md1") containing the specified member, or "" if the
// array is not running or there is no such member.
-Glib::ustring SWRaid_Info::get_array( const Glib::ustring & member_path )
+const Glib::ustring& SWRaid_Info::get_array(const Glib::ustring& member_path)
{
initialise_if_required();
const SWRaid_Member & memb = get_cache_entry_by_member( member_path );
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]