From 74b34fe239d7881cb0e5881fc866100952157f38 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 10 Oct 2008 17:11:13 +0100 Subject: [PATCH] [default] Use the slice allocator The actor's private data created by the compositor is allocated using g_new(), but since we are allocating a lot of small structures all the time it's better to use the slice allocator instead. Also, use a GQuark instead of using a string, so that the quark lookup is done only once and the rest of the time is just an integer comparison. --- .../clutter/clutter-plugins/default.c | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/compositor/clutter/clutter-plugins/default.c b/src/compositor/clutter/clutter-plugins/default.c index d4c8e7208..92243d00a 100644 --- a/src/compositor/clutter/clutter-plugins/default.c +++ b/src/compositor/clutter/clutter-plugins/default.c @@ -40,6 +40,7 @@ #define SWITCH_TIMEOUT 500 #define ACTOR_DATA_KEY "MCCP-Default-actor-data" +static GQuark actor_data_quark = 0; typedef struct PluginPrivate PluginPrivate; typedef struct ActorPrivate ActorPrivate; @@ -140,15 +141,28 @@ struct ActorPrivate /* * Actor private data accessor */ +static void +free_actor_private (gpointer data) +{ + if (G_LIKELY (data != NULL)) + g_slice_free (ActorPrivate, data); +} + static ActorPrivate * get_actor_private (MetaCompWindow *actor) { - ActorPrivate * priv = g_object_get_data (G_OBJECT (actor), ACTOR_DATA_KEY); + ActorPrivate *priv = g_object_get_qdata (G_OBJECT (actor), actor_data_quark); - if (!priv) + if (G_UNLIKELY (actor_data_quark == 0)) + actor_data_quark = g_quark_from_static_string (ACTOR_DATA_KEY); + + if (G_UNLIKELY (!priv)) { - priv = g_new0 (ActorPrivate, 1); - g_object_set_data_full (G_OBJECT (actor), ACTOR_DATA_KEY, priv, g_free); + priv = g_slice_new0 (ActorPrivate); + + g_object_set_qdata_full (G_OBJECT (actor), + actor_data_quark, priv, + free_actor_private); } return priv;