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

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