From f935270aa01ac83ecb43212cb86bac63e76d5687 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 19 Mar 2010 16:24:34 +0000 Subject: [PATCH] script: Do not allocate memory when not needed When printing out the property value during a ClutterScript debug run we generate the value's content using g_strdup_value_contents() - though we do it unconditionally. The contents might not be printed (they most likely won't, actually) and will be freed afterwards. This is unnecessary: we can allocate the contents string after checking if we're going to print out the debug note, thus avoiding the whole allocation/free cycle unless strictly needed. --- clutter/clutter-actor.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c index cf478a9c2..1b6c0fa84 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -8037,17 +8037,18 @@ clutter_actor_set_custom_property (ClutterScriptable *scriptable, const GValue *value) { #ifdef CLUTTER_ENABLE_DEBUG - { - gchar *tmp = g_strdup_value_contents (value); + if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_SCRIPT)) + { + gchar *tmp = g_strdup_value_contents (value); - CLUTTER_NOTE (SCRIPT, - "in ClutterActor::set_custom_property('%s') = %s", - name, - tmp); + CLUTTER_NOTE (SCRIPT, + "in ClutterActor::set_custom_property('%s') = %s", + name, + tmp); - g_free (tmp); - } -#endif + g_free (tmp); + } +#endif /* CLUTTER_ENABLE_DEBUG */ if (strcmp (name, "rotation") == 0) {