actor: Minor optimization to avoid get_preferred_*
authorEmmanuele Bassi <ebassi@linux.intel.com>
Wed, 28 Mar 2012 17:07:06 +0000 (18:07 +0100)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Wed, 28 Mar 2012 17:07:06 +0000 (18:07 +0100)
When the easing state has a duration of zero milliseconds we can skip
the entire create_transition() call inside set_width() and set_height(),
to avoid what may be a costly call to get_preferred_*.

clutter/clutter-actor.c

index e450c7a..084d033 100644 (file)
@@ -9473,7 +9473,25 @@ clutter_actor_set_width (ClutterActor *self,
 
   if (_clutter_actor_get_transition (self, obj_props[PROP_WIDTH]) == NULL)
     {
-      float cur_size = clutter_actor_get_width (self);
+      float cur_size;
+
+      /* minor optimization: if we don't have a duration
+       * then we can skip the get_width() below, to avoid
+       * the chance of going through get_preferred_width()
+       * just to jump to a new desired width.
+       */
+      if (clutter_actor_get_easing_duration (self) == 0)
+        {
+          g_object_freeze_notify (G_OBJECT (self));
+
+          clutter_actor_set_width_internal (self, width);
+
+          g_object_thaw_notify (G_OBJECT (self));
+
+          return;
+        }
+      else
+        cur_size = clutter_actor_get_width (self);
 
       _clutter_actor_create_transition (self,
                                         obj_props[PROP_WIDTH],
@@ -9509,7 +9527,21 @@ clutter_actor_set_height (ClutterActor *self,
 
   if (_clutter_actor_get_transition (self, obj_props[PROP_HEIGHT]) == NULL)
     {
-      float cur_size = clutter_actor_get_height (self);
+      float cur_size;
+
+      /* see the comment in clutter_actor_set_width() above */
+      if (clutter_actor_get_easing_duration (self) == 0)
+        {
+          g_object_freeze_notify (G_OBJECT (self));
+
+          clutter_actor_set_height_internal (self, height);
+
+          g_object_thaw_notify (G_OBJECT (self));
+
+          return;
+        }
+      else
+        cur_size = clutter_actor_get_height (self);
 
       _clutter_actor_create_transition (self,
                                         obj_props[PROP_HEIGHT],