[mutter] Use free_full on GList's instead of foreach + free



commit df7d8e2cbfdea5f8d7b9758ae8507e0fcd77a3c2
Author: Marco Trevisan (Treviño) <mail 3v1n0 net>
Date:   Wed May 15 13:56:06 2019 -0500

    Use free_full on GList's instead of foreach + free
    
    GList's used in legacy code were free'd using a g_list_foreach + g_list_free,
    while we can just use g_list_free_full as per GLib 2.28.
    
    So replace code where we were using this legacy codepath.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/576

 clutter/clutter/cally/cally-actor.c     |  6 ++----
 clutter/clutter/clutter-actor-meta.c    |  3 +--
 clutter/clutter/clutter-script-parser.c |  3 +--
 clutter/clutter/clutter-script.c        |  9 +++------
 clutter/tests/conform/actor-destroy.c   |  3 +--
 cogl/cogl/cogl-pipeline.c               | 13 ++-----------
 src/core/boxes.c                        |  5 +----
 7 files changed, 11 insertions(+), 31 deletions(-)
---
diff --git a/clutter/clutter/cally/cally-actor.c b/clutter/clutter/cally/cally-actor.c
index 548615f48..1c2137807 100644
--- a/clutter/clutter/cally/cally-actor.c
+++ b/clutter/clutter/cally/cally-actor.c
@@ -1044,10 +1044,8 @@ _cally_actor_clean_action_list (CallyActor *cally_actor)
 
   if (priv->action_list)
     {
-      g_list_foreach (priv->action_list,
-                      (GFunc) _cally_actor_destroy_action_info,
-                      NULL);
-      g_list_free (priv->action_list);
+      g_list_free_full (priv->action_list,
+                        (GDestroyNotify) _cally_actor_destroy_action_info);
       priv->action_list = NULL;
     }
 }
diff --git a/clutter/clutter/clutter-actor-meta.c b/clutter/clutter/clutter-actor-meta.c
index 4650d90a1..d7f4fd785 100644
--- a/clutter/clutter/clutter-actor-meta.c
+++ b/clutter/clutter/clutter-actor-meta.c
@@ -577,8 +577,7 @@ _clutter_meta_group_clear_metas (ClutterMetaGroup *group)
 {
   g_list_foreach (group->meta, (GFunc) _clutter_actor_meta_set_actor, NULL);
 
-  g_list_foreach (group->meta, (GFunc) g_object_unref, NULL);
-  g_list_free (group->meta);
+  g_list_free_full (group->meta, g_object_unref);
   group->meta = NULL;
 }
 
diff --git a/clutter/clutter/clutter-script-parser.c b/clutter/clutter/clutter-script-parser.c
index 55e70dac9..9c6dfca32 100644
--- a/clutter/clutter/clutter-script-parser.c
+++ b/clutter/clutter/clutter-script-parser.c
@@ -2021,8 +2021,7 @@ add_children (ClutterScript *script,
       clutter_container_add_actor (container, CLUTTER_ACTOR (object));
     }
 
-  g_list_foreach (oinfo->children, (GFunc) g_free, NULL);
-  g_list_free (oinfo->children);
+  g_list_free_full (oinfo->children, g_free);
 
   oinfo->children = unresolved;
 }
diff --git a/clutter/clutter/clutter-script.c b/clutter/clutter/clutter-script.c
index 7a58cd0fb..a62fb4ca9 100644
--- a/clutter/clutter/clutter-script.c
+++ b/clutter/clutter/clutter-script.c
@@ -346,15 +346,12 @@ object_info_free (gpointer data)
       g_free (oinfo->class_name);
       g_free (oinfo->type_func);
 
-      g_list_foreach (oinfo->properties, (GFunc) property_info_free, NULL);
-      g_list_free (oinfo->properties);
+      g_list_free_full (oinfo->properties, property_info_free);
 
-      g_list_foreach (oinfo->signals, (GFunc) signal_info_free, NULL);
-      g_list_free (oinfo->signals);
+      g_list_free_full (oinfo->signals, signal_info_free);
 
       /* these are ids */
-      g_list_foreach (oinfo->children, (GFunc) g_free, NULL);
-      g_list_free (oinfo->children);
+      g_list_free_full (oinfo->children, g_free);
 
       /* we unref top-level objects and leave the actors alone,
        * unless we are unmerging in which case we have to destroy
diff --git a/clutter/tests/conform/actor-destroy.c b/clutter/tests/conform/actor-destroy.c
index 03092a010..4677c9537 100644
--- a/clutter/tests/conform/actor-destroy.c
+++ b/clutter/tests/conform/actor-destroy.c
@@ -114,8 +114,7 @@ test_destroy_destroy (ClutterActor *self)
       test->tex = NULL;
     }
 
-  g_list_foreach (test->children, (GFunc) clutter_actor_destroy, NULL);
-  g_list_free (test->children);
+  g_list_free_full (test->children, (GDestroyNotify) clutter_actor_destroy);
   test->children = NULL;
 
   if (CLUTTER_ACTOR_CLASS (test_destroy_parent_class)->destroy)
diff --git a/cogl/cogl/cogl-pipeline.c b/cogl/cogl/cogl-pipeline.c
index 6d88c44f6..61487e11b 100644
--- a/cogl/cogl/cogl-pipeline.c
+++ b/cogl/cogl/cogl-pipeline.c
@@ -456,11 +456,7 @@ _cogl_pipeline_free (CoglPipeline *pipeline)
     g_slice_free (CoglPipelineBigState, pipeline->big_state);
 
   if (pipeline->differences & COGL_PIPELINE_STATE_LAYERS)
-    {
-      g_list_foreach (pipeline->layer_differences,
-                      (GFunc)cogl_object_unref, NULL);
-      g_list_free (pipeline->layer_differences);
-    }
+    g_list_free_full (pipeline->layer_differences, cogl_object_unref);
 
   if (pipeline->differences & COGL_PIPELINE_STATE_VERTEX_SNIPPETS)
     _cogl_pipeline_snippet_list_free (&pipeline->big_state->vertex_snippets);
@@ -937,12 +933,7 @@ _cogl_pipeline_copy_differences (CoglPipeline *dest,
 
       if (dest->differences & COGL_PIPELINE_STATE_LAYERS &&
           dest->layer_differences)
-        {
-          g_list_foreach (dest->layer_differences,
-                          (GFunc)cogl_object_unref,
-                          NULL);
-          g_list_free (dest->layer_differences);
-        }
+        g_list_free_full (dest->layer_differences, cogl_object_unref);
 
       for (l = src->layer_differences; l; l = l->next)
         {
diff --git a/src/core/boxes.c b/src/core/boxes.c
index 4bb961c5e..400febea1 100644
--- a/src/core/boxes.c
+++ b/src/core/boxes.c
@@ -851,10 +851,7 @@ meta_rectangle_expand_to_avoiding_struts (MetaRectangle       *rect,
 void
 meta_rectangle_free_list_and_elements (GList *filled_list)
 {
-  g_list_foreach (filled_list,
-                  (void (*)(gpointer,gpointer))&g_free, /* ew, for ugly */
-                  NULL);
-  g_list_free (filled_list);
+  g_list_free_full (filled_list, g_free);
 }
 
 gboolean


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