Blame SOURCES/0002-clutter-avoid-g_signal_emit_by_name-from-ClutterActo.patch

f92192
From 04e5e144ce21c811601e169c13fdef7b8edeae12 Mon Sep 17 00:00:00 2001
f92192
From: Christian Hergert <christian@hergert.me>
f92192
Date: Mon, 24 Feb 2020 22:36:27 +0000
f92192
Subject: [PATCH 2/3] clutter: avoid g_signal_emit_by_name() from ClutterActor
f92192
f92192
g_signal_emit_by_name() is used to emit signals on ClutterContainer when
f92192
actors are removed or added. It happens to do various interface lookups
f92192
which are a bit unneccessary and can allocate memory.
f92192
f92192
Simply using emission wrappers makes all of that go away.
f92192
f92192
https://gitlab.gnome.org/GNOME/mutter/merge_requests/1083
f92192
---
f92192
 clutter/clutter/cally/cally-actor.c         |  5 +--
f92192
 clutter/clutter/clutter-actor.c             | 17 ++++++++--
f92192
 clutter/clutter/clutter-actor.h             |  5 ++-
f92192
 clutter/clutter/clutter-container-private.h | 36 +++++++++++++++++++++
f92192
 clutter/clutter/clutter-container.c         | 21 ++++++++++++
f92192
 5 files changed, 78 insertions(+), 6 deletions(-)
f92192
 create mode 100644 clutter/clutter/clutter-container-private.h
f92192
f92192
diff --git a/clutter/clutter/cally/cally-actor.c b/clutter/clutter/cally/cally-actor.c
f92192
index f341d3616..77195c0b0 100644
f92192
--- a/clutter/clutter/cally/cally-actor.c
f92192
+++ b/clutter/clutter/cally/cally-actor.c
f92192
@@ -606,10 +606,11 @@ cally_actor_real_remove_actor (ClutterActor *container,
f92192
   g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), 0);
f92192
 
f92192
   atk_parent = ATK_OBJECT (data);
f92192
-  atk_child = clutter_actor_get_accessible (actor);
f92192
 
f92192
-  if (atk_child)
f92192
+  if (clutter_actor_has_accessible (actor))
f92192
     {
f92192
+      atk_child = clutter_actor_get_accessible (actor);
f92192
+
f92192
       g_value_init (&values.old_value, G_TYPE_POINTER);
f92192
       g_value_set_pointer (&values.old_value, atk_parent);
f92192
 
f92192
diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c
f92192
index 6954f0396..8da53d3f1 100644
f92192
--- a/clutter/clutter/clutter-actor.c
f92192
+++ b/clutter/clutter/clutter-actor.c
f92192
@@ -624,7 +624,7 @@
f92192
 #include "clutter-color-static.h"
f92192
 #include "clutter-color.h"
f92192
 #include "clutter-constraint-private.h"
f92192
-#include "clutter-container.h"
f92192
+#include "clutter-container-private.h"
f92192
 #include "clutter-content-private.h"
f92192
 #include "clutter-debug.h"
f92192
 #include "clutter-easing.h"
f92192
@@ -4310,7 +4310,7 @@ clutter_actor_remove_child_internal (ClutterActor                 *self,
f92192
 
f92192
   /* we need to emit the signal before dropping the reference */
f92192
   if (emit_actor_removed)
f92192
-    g_signal_emit_by_name (self, "actor-removed", child);
f92192
+    _clutter_container_emit_actor_removed (CLUTTER_CONTAINER (self), child);
f92192
 
f92192
   if (notify_first_last)
f92192
     {
f92192
@@ -12980,7 +12980,7 @@ clutter_actor_add_child_internal (ClutterActor              *self,
f92192
     }
f92192
 
f92192
   if (emit_actor_added)
f92192
-    g_signal_emit_by_name (self, "actor-added", child);
f92192
+    _clutter_container_emit_actor_added (CLUTTER_CONTAINER (self), child);
f92192
 
f92192
   if (notify_first_last)
f92192
     {
f92192
@@ -21150,3 +21150,14 @@ clutter_actor_create_texture_paint_node (ClutterActor *self,
f92192
 
f92192
   return node;
f92192
 }
f92192
+
f92192
+gboolean
f92192
+clutter_actor_has_accessible (ClutterActor *actor)
f92192
+{
f92192
+  g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), FALSE);
f92192
+
f92192
+  if (CLUTTER_ACTOR_GET_CLASS (actor)->has_accessible)
f92192
+    return CLUTTER_ACTOR_GET_CLASS (actor)->has_accessible (actor);
f92192
+
f92192
+  return TRUE;
f92192
+}
f92192
diff --git a/clutter/clutter/clutter-actor.h b/clutter/clutter/clutter-actor.h
f92192
index 0c5a08c8c..9b0665c72 100644
f92192
--- a/clutter/clutter/clutter-actor.h
f92192
+++ b/clutter/clutter/clutter-actor.h
f92192
@@ -295,10 +295,11 @@ struct _ClutterActorClass
f92192
 
f92192
   gboolean (* touch_event)          (ClutterActor         *self,
f92192
                                      ClutterTouchEvent    *event);
f92192
+  gboolean (* has_accessible)       (ClutterActor         *self);
f92192
 
f92192
   /*< private >*/
f92192
   /* padding for future expansion */
f92192
-  gpointer _padding_dummy[26];
f92192
+  gpointer _padding_dummy[25];
f92192
 };
f92192
 
f92192
 /**
f92192
@@ -368,6 +369,8 @@ CLUTTER_AVAILABLE_IN_ALL
f92192
 const gchar *                   clutter_actor_get_name                          (ClutterActor                *self);
f92192
 CLUTTER_AVAILABLE_IN_ALL
f92192
 AtkObject *                     clutter_actor_get_accessible                    (ClutterActor                *self);
f92192
+CLUTTER_AVAILABLE_IN_ALL
f92192
+gboolean                        clutter_actor_has_accessible                    (ClutterActor                *self);
f92192
 
f92192
 CLUTTER_AVAILABLE_IN_1_24
f92192
 gboolean                        clutter_actor_is_visible                        (ClutterActor                *self);
f92192
diff --git a/clutter/clutter/clutter-container-private.h b/clutter/clutter/clutter-container-private.h
f92192
new file mode 100644
f92192
index 000000000..d619a6531
f92192
--- /dev/null
f92192
+++ b/clutter/clutter/clutter-container-private.h
f92192
@@ -0,0 +1,36 @@
f92192
+/*
f92192
+ * Clutter.
f92192
+ *
f92192
+ * An OpenGL based 'interactive canvas' library.
f92192
+ *
f92192
+ * Copyright 2020 Red Hat, Inc.
f92192
+ *
f92192
+ * This library is free software; you can redistribute it and/or
f92192
+ * modify it under the terms of the GNU Lesser General Public
f92192
+ * License as published by the Free Software Foundation; either
f92192
+ * version 2 of the License, or (at your option) any later version.
f92192
+ *
f92192
+ * This library is distributed in the hope that it will be useful,
f92192
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
f92192
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
f92192
+ * Lesser General Public License for more details.
f92192
+ *
f92192
+ * You should have received a copy of the GNU Lesser General Public
f92192
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
f92192
+ */
f92192
+
f92192
+#ifndef __CLUTTER_CONTAINER_PRIVATE_H__
f92192
+#define __CLUTTER_CONTAINER_PRIVATE_H__
f92192
+
f92192
+#include <clutter/clutter-container.h>
f92192
+
f92192
+G_BEGIN_DECLS
f92192
+
f92192
+void _clutter_container_emit_actor_added   (ClutterContainer *container,
f92192
+                                            ClutterActor     *actor);
f92192
+void _clutter_container_emit_actor_removed (ClutterContainer *container,
f92192
+                                            ClutterActor     *actor);
f92192
+
f92192
+G_END_DECLS
f92192
+
f92192
+#endif /* __CLUTTER_CONTAINER_PRIVATE_H__ */
f92192
diff --git a/clutter/clutter/clutter-container.c b/clutter/clutter/clutter-container.c
f92192
index 81fe4dc2e..52942a246 100644
f92192
--- a/clutter/clutter/clutter-container.c
f92192
+++ b/clutter/clutter/clutter-container.c
f92192
@@ -39,6 +39,7 @@
f92192
 
f92192
 #include "clutter-actor-private.h"
f92192
 #include "clutter-child-meta.h"
f92192
+#include "clutter-container-private.h"
f92192
 #include "clutter-debug.h"
f92192
 #include "clutter-main.h"
f92192
 #include "clutter-marshal.h"
f92192
@@ -1448,3 +1449,23 @@ clutter_container_child_notify (ClutterContainer *container,
f92192
                                                          child,
f92192
                                                          pspec);
f92192
 }
f92192
+
f92192
+void
f92192
+_clutter_container_emit_actor_added (ClutterContainer *container,
f92192
+                                     ClutterActor     *actor)
f92192
+{
f92192
+  g_return_if_fail (CLUTTER_IS_CONTAINER (container));
f92192
+  g_return_if_fail (CLUTTER_IS_ACTOR (actor));
f92192
+
f92192
+  g_signal_emit (container, container_signals[ACTOR_ADDED], 0, actor);
f92192
+}
f92192
+
f92192
+void
f92192
+_clutter_container_emit_actor_removed (ClutterContainer *container,
f92192
+                                       ClutterActor     *actor)
f92192
+{
f92192
+  g_return_if_fail (CLUTTER_IS_CONTAINER (container));
f92192
+  g_return_if_fail (CLUTTER_IS_ACTOR (actor));
f92192
+
f92192
+  g_signal_emit (container, container_signals[ACTOR_REMOVED], 0, actor);
f92192
+}
f92192
-- 
f92192
2.26.0
f92192