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.
This commit is contained in:
Emmanuele Bassi 2010-03-19 16:24:34 +00:00
parent a39cef41b8
commit f935270aa0

View File

@ -8037,17 +8037,18 @@ clutter_actor_set_custom_property (ClutterScriptable *scriptable,
const GValue *value) const GValue *value)
{ {
#ifdef CLUTTER_ENABLE_DEBUG #ifdef CLUTTER_ENABLE_DEBUG
{ if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_SCRIPT))
gchar *tmp = g_strdup_value_contents (value); {
gchar *tmp = g_strdup_value_contents (value);
CLUTTER_NOTE (SCRIPT, CLUTTER_NOTE (SCRIPT,
"in ClutterActor::set_custom_property('%s') = %s", "in ClutterActor::set_custom_property('%s') = %s",
name, name,
tmp); tmp);
g_free (tmp); g_free (tmp);
} }
#endif #endif /* CLUTTER_ENABLE_DEBUG */
if (strcmp (name, "rotation") == 0) if (strcmp (name, "rotation") == 0)
{ {