[calls] call-window: Improve readability of remove_call function



commit 2fc5533e1a317d940e47928a322aa50791f20a3d
Author: Evangelos Ribeiro Tzaras <devrtz fortysixandtwo eu>
Date:   Thu Oct 28 14:58:34 2021 +0200

    call-window: Improve readability of remove_call function
    
    The casual reader might be tricked into believing CallsCallSelectorItem would
    leak here, which was not actually the case.

 src/calls-call-window.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
---
diff --git a/src/calls-call-window.c b/src/calls-call-window.c
index 3f03a1cd..2a117ad3 100644
--- a/src/calls-call-window.c
+++ b/src/calls-call-window.c
@@ -182,29 +182,23 @@ remove_call (CallsCallWindow *self,
              CallsCall       *call,
              const gchar     *reason)
 {
-  g_autoptr (CallsCallSelectorItem) item = NULL;
-  gint position;
+  guint n_calls;
 
   g_return_if_fail (CALLS_IS_CALL_WINDOW (self));
   g_return_if_fail (CALLS_IS_CALL (call));
 
-  position = 0;
-  item = g_list_model_get_item (G_LIST_MODEL (self->calls), position);
-  while (item != NULL) {
+  n_calls = g_list_model_get_n_items (G_LIST_MODEL (self->calls));
+  for (guint i = 0; i < n_calls; i++) {
+    g_autoptr (CallsCallSelectorItem) item =
+      g_list_model_get_item (G_LIST_MODEL (self->calls), i);
     CallsCallDisplay *display = calls_call_selector_item_get_display (item);
 
     if (calls_call_display_get_call (display) == call) {
-      g_list_store_remove (self->calls, position);
+      g_list_store_remove (self->calls, i);
       gtk_container_remove (GTK_CONTAINER (self->call_stack),
                             GTK_WIDGET (display));
-
-
       break;
     }
-
-    g_object_unref (item);
-    position++;
-    item = g_list_model_get_item (G_LIST_MODEL (self->calls), position);
   }
 
   update_visibility (self);


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