[gnome-control-center/wip/benzea/wifi-panel: 1/4] wifi: Avoid one level of indentation



commit 6a5db9b3dc3626c41d3519bf360b5be66e18f8c5
Author: Benjamin Berg <bberg redhat com>
Date:   Thu Dec 13 10:46:28 2018 +0100

    wifi: Avoid one level of indentation
    
    Convert an if into an early return rather than nesting the entire logic.

 panels/network/net-device-wifi.c | 78 ++++++++++++++++++++--------------------
 1 file changed, 40 insertions(+), 38 deletions(-)
---
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index 262e8122f..c2244c307 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -165,54 +165,56 @@ panel_get_strongest_unique_aps (const GPtrArray *aps)
         /* we will have multiple entries for typical hotspots, just
          * filter to the one with the strongest signal */
         aps_unique = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
-        if (aps != NULL)
-                for (i = 0; i < aps->len; i++) {
-                        ap = NM_ACCESS_POINT (g_ptr_array_index (aps, i));
+        if (aps == NULL)
+                return aps_unique;
 
-                        /* Hidden SSIDs don't get shown in the list */
-                        ssid = nm_access_point_get_ssid (ap);
-                        if (!ssid)
-                                continue;
+        for (i = 0; i < aps->len; i++) {
+                ap = NM_ACCESS_POINT (g_ptr_array_index (aps, i));
 
-                        add_ap = TRUE;
+                /* Hidden SSIDs don't get shown in the list */
+                ssid = nm_access_point_get_ssid (ap);
+                if (!ssid)
+                        continue;
 
-                        /* get already added list */
-                        for (j=0; j<aps_unique->len; j++) {
-                                ap_tmp = NM_ACCESS_POINT (g_ptr_array_index (aps_unique, j));
-                                ssid_tmp = nm_access_point_get_ssid (ap_tmp);
-                                g_assert (ssid_tmp);
+                add_ap = TRUE;
 
-                                /* is this the same type and data? */
-                                if (nm_utils_same_ssid (g_bytes_get_data (ssid, NULL), g_bytes_get_size 
(ssid),
-                                                        g_bytes_get_data (ssid_tmp, NULL), g_bytes_get_size 
(ssid_tmp),
-                                                        TRUE)) {
+                /* get already added list */
+                for (j=0; j<aps_unique->len; j++) {
+                        ap_tmp = NM_ACCESS_POINT (g_ptr_array_index (aps_unique, j));
+                        ssid_tmp = nm_access_point_get_ssid (ap_tmp);
+                        g_assert (ssid_tmp);
+
+                        /* is this the same type and data? */
+                        if (nm_utils_same_ssid (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid),
+                                                g_bytes_get_data (ssid_tmp, NULL), g_bytes_get_size 
(ssid_tmp),
+                                                TRUE)) {
 
-                                        g_debug ("found duplicate: %s",
+                                g_debug ("found duplicate: %s",
+                                         nm_utils_escape_ssid (g_bytes_get_data (ssid_tmp, NULL),
+                                                               g_bytes_get_size (ssid_tmp)));
+
+                                /* the new access point is stronger */
+                                if (nm_access_point_get_strength (ap) >
+                                    nm_access_point_get_strength (ap_tmp)) {
+                                        g_debug ("removing %s",
                                                  nm_utils_escape_ssid (g_bytes_get_data (ssid_tmp, NULL),
                                                                        g_bytes_get_size (ssid_tmp)));
-
-                                        /* the new access point is stronger */
-                                        if (nm_access_point_get_strength (ap) >
-                                            nm_access_point_get_strength (ap_tmp)) {
-                                                g_debug ("removing %s",
-                                                         nm_utils_escape_ssid (g_bytes_get_data (ssid_tmp, 
NULL),
-                                                                               g_bytes_get_size (ssid_tmp)));
-                                                g_ptr_array_remove (aps_unique, ap_tmp);
-                                                add_ap = TRUE;
-                                        } else {
-                                                add_ap = FALSE;
-                                        }
-
-                                        break;
+                                        g_ptr_array_remove (aps_unique, ap_tmp);
+                                        add_ap = TRUE;
+                                } else {
+                                        add_ap = FALSE;
                                 }
+
+                                break;
                         }
-                        if (add_ap) {
-                                g_debug ("adding %s",
-                                         nm_utils_escape_ssid (g_bytes_get_data (ssid, NULL),
-                                                               g_bytes_get_size (ssid)));
-                                g_ptr_array_add (aps_unique, g_object_ref (ap));
-                        }
                 }
+                if (add_ap) {
+                        g_debug ("adding %s",
+                                 nm_utils_escape_ssid (g_bytes_get_data (ssid, NULL),
+                                                       g_bytes_get_size (ssid)));
+                        g_ptr_array_add (aps_unique, g_object_ref (ap));
+                }
+        }
         return aps_unique;
 }
 


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