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

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