[gnome-bluetooth/wip/hadess/use-alias: 2/5] settings-widget: Simplify sorting function
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth/wip/hadess/use-alias: 2/5] settings-widget: Simplify sorting function
- Date: Wed, 9 Dec 2020 14:40:49 +0000 (UTC)
commit 74e15fac52b0f1a2b720e1bb4aa1f5a322c3adf8
Author: Bastien Nocera <hadess hadess net>
Date: Wed Dec 9 15:20:10 2020 +0100
settings-widget: Simplify sorting function
Use g_autofree to get rid of a number of gotos.
lib/bluetooth-settings-widget.c | 33 +++++++++++----------------------
1 file changed, 11 insertions(+), 22 deletions(-)
---
diff --git a/lib/bluetooth-settings-widget.c b/lib/bluetooth-settings-widget.c
index 08d9d47e..74f82cc0 100644
--- a/lib/bluetooth-settings-widget.c
+++ b/lib/bluetooth-settings-widget.c
@@ -1406,8 +1406,8 @@ device_sort_func (gconstpointer a, gconstpointer b, gpointer data)
gboolean paired_a, paired_b;
gboolean trusted_a, trusted_b;
gboolean connected_a, connected_b;
- char *name_a, *name_b;
- int ret;
+ g_autofree char *name_a = NULL;
+ g_autofree char *name_b = NULL;
g_object_get (row_a,
"paired", &paired_a,
@@ -1427,37 +1427,26 @@ device_sort_func (gconstpointer a, gconstpointer b, gpointer data)
setup_b = paired_b || trusted_b;
if (setup_a != setup_b) {
if (setup_a)
- ret = -1;
+ return -1;
else
- ret = 1;
- goto out;
+ return 1;
}
/* Then connected ones */
if (connected_a != connected_b) {
if (connected_a)
- ret = -1;
+ return -1;
else
- ret = 1;
- goto out;
+ return 1;
}
- if (name_a == NULL) {
- ret = 1;
- goto out;
- }
- if (name_b == NULL) {
- ret = -1;
- goto out;
- }
+ if (name_a == NULL)
+ return 1;
+ if (name_b == NULL)
+ return -1;
/* And all being equal, alphabetically */
- ret = g_utf8_collate (name_a, name_b);
-
-out:
- g_free (name_a);
- g_free (name_b);
- return ret;
+ return g_utf8_collate (name_a, name_b);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]