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

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