Begin porting layout managers to the new child iteration API

Instead of getting the list of children to iterate over it, let's use
the newly added child iteration API; this should save us a bunch of
allocations, as well as indirections.

Ported: ClutterBinLayout and ClutterBoxLayout.
This commit is contained in:
Emmanuele Bassi 2011-12-18 10:29:01 +00:00
parent 8b430507b5
commit 9c9ab42060
2 changed files with 53 additions and 67 deletions

View File

@ -335,15 +335,16 @@ clutter_bin_layout_get_preferred_width (ClutterLayoutManager *manager,
gfloat *min_width_p, gfloat *min_width_p,
gfloat *nat_width_p) gfloat *nat_width_p)
{ {
GList *children = clutter_container_get_children (container); ClutterActor *actor = CLUTTER_ACTOR (container);
GList *l; ClutterActor *child;
gfloat min_width, nat_width; gfloat min_width, nat_width;
min_width = nat_width = 0.0; min_width = nat_width = 0.0;
for (l = children; l != NULL; l = l->next) for (child = clutter_actor_get_first_child (actor);
child != NULL;
child = clutter_actor_get_next_sibling (child))
{ {
ClutterActor *child = l->data;
gfloat minimum, natural; gfloat minimum, natural;
clutter_actor_get_preferred_width (child, for_height, clutter_actor_get_preferred_width (child, for_height,
@ -359,8 +360,6 @@ clutter_bin_layout_get_preferred_width (ClutterLayoutManager *manager,
if (nat_width_p) if (nat_width_p)
*nat_width_p = nat_width; *nat_width_p = nat_width;
g_list_free (children);
} }
static void static void
@ -370,15 +369,16 @@ clutter_bin_layout_get_preferred_height (ClutterLayoutManager *manager,
gfloat *min_height_p, gfloat *min_height_p,
gfloat *nat_height_p) gfloat *nat_height_p)
{ {
GList *children = clutter_container_get_children (container); ClutterActor *actor = CLUTTER_ACTOR (container);
GList *l; ClutterActor *child;
gfloat min_height, nat_height; gfloat min_height, nat_height;
min_height = nat_height = 0.0; min_height = nat_height = 0.0;
for (l = children; l != NULL; l = l->next) for (child = clutter_actor_get_first_child (actor);
child != NULL;
child = clutter_actor_get_next_sibling (child))
{ {
ClutterActor *child = l->data;
gfloat minimum, natural; gfloat minimum, natural;
clutter_actor_get_preferred_height (child, for_width, clutter_actor_get_preferred_height (child, for_width,
@ -394,8 +394,6 @@ clutter_bin_layout_get_preferred_height (ClutterLayoutManager *manager,
if (nat_height_p) if (nat_height_p)
*nat_height_p = nat_height; *nat_height_p = nat_height;
g_list_free (children);
} }
static gdouble static gdouble
@ -426,17 +424,19 @@ clutter_bin_layout_allocate (ClutterLayoutManager *manager,
const ClutterActorBox *allocation, const ClutterActorBox *allocation,
ClutterAllocationFlags flags) ClutterAllocationFlags flags)
{ {
GList *children = clutter_container_get_children (container);
GList *l;
gfloat allocation_x, allocation_y; gfloat allocation_x, allocation_y;
gfloat available_w, available_h; gfloat available_w, available_h;
ClutterActor *actor, *child;
clutter_actor_box_get_origin (allocation, &allocation_x, &allocation_y); clutter_actor_box_get_origin (allocation, &allocation_x, &allocation_y);
clutter_actor_box_get_size (allocation, &available_w, &available_h); clutter_actor_box_get_size (allocation, &available_w, &available_h);
for (l = children; l != NULL; l = l->next) actor = CLUTTER_ACTOR (container);
for (child = clutter_actor_get_first_child (actor);
child != NULL;
child = clutter_actor_get_next_sibling (child))
{ {
ClutterActor *child = l->data;
ClutterLayoutMeta *meta; ClutterLayoutMeta *meta;
ClutterBinLayer *layer; ClutterBinLayer *layer;
ClutterActorBox child_alloc = { 0, }; ClutterActorBox child_alloc = { 0, };
@ -471,8 +471,6 @@ clutter_bin_layout_allocate (ClutterLayoutManager *manager,
x_fill, y_fill, x_fill, y_fill,
flags); flags);
} }
g_list_free (children);
} }
static GType static GType

View File

@ -476,16 +476,15 @@ clutter_box_layout_set_container (ClutterLayoutManager *layout,
static void static void
get_preferred_width (ClutterBoxLayout *self, get_preferred_width (ClutterBoxLayout *self,
ClutterContainer *container, ClutterActor *container,
GList *children,
gfloat for_height, gfloat for_height,
gfloat *min_width_p, gfloat *min_width_p,
gfloat *natural_width_p) gfloat *natural_width_p)
{ {
ClutterBoxLayoutPrivate *priv = self->priv; ClutterBoxLayoutPrivate *priv = self->priv;
ClutterActor *child;
gint n_children = 0; gint n_children = 0;
gboolean is_rtl; gboolean is_rtl;
GList *l;
if (min_width_p) if (min_width_p)
*min_width_p = 0; *min_width_p = 0;
@ -497,17 +496,18 @@ get_preferred_width (ClutterBoxLayout *self,
{ {
ClutterTextDirection text_dir; ClutterTextDirection text_dir;
text_dir = clutter_actor_get_text_direction (CLUTTER_ACTOR (container)); text_dir = clutter_actor_get_text_direction (container);
is_rtl = (text_dir == CLUTTER_TEXT_DIRECTION_RTL) ? TRUE : FALSE; is_rtl = (text_dir == CLUTTER_TEXT_DIRECTION_RTL) ? TRUE : FALSE;
} }
else else
is_rtl = FALSE; is_rtl = FALSE;
for (l = (is_rtl) ? g_list_last (children) : children; for (child = (is_rtl) ? clutter_actor_get_last_child (container)
l != NULL; : clutter_actor_get_first_child (container);
l = (is_rtl) ? l->prev : l->next) child != NULL;
child = (is_rtl) ? clutter_actor_get_previous_sibling (child)
: clutter_actor_get_next_sibling (child))
{ {
ClutterActor *child = l->data;
gfloat child_min = 0, child_nat = 0; gfloat child_min = 0, child_nat = 0;
if (!CLUTTER_ACTOR_IS_VISIBLE (child)) if (!CLUTTER_ACTOR_IS_VISIBLE (child))
@ -553,16 +553,15 @@ get_preferred_width (ClutterBoxLayout *self,
static void static void
get_preferred_height (ClutterBoxLayout *self, get_preferred_height (ClutterBoxLayout *self,
ClutterContainer *container, ClutterActor *container,
GList *children,
gfloat for_width, gfloat for_width,
gfloat *min_height_p, gfloat *min_height_p,
gfloat *natural_height_p) gfloat *natural_height_p)
{ {
ClutterBoxLayoutPrivate *priv = self->priv; ClutterBoxLayoutPrivate *priv = self->priv;
ClutterActor *child;
gint n_children = 0; gint n_children = 0;
gboolean is_rtl; gboolean is_rtl;
GList *l;
if (min_height_p) if (min_height_p)
*min_height_p = 0; *min_height_p = 0;
@ -574,17 +573,18 @@ get_preferred_height (ClutterBoxLayout *self,
{ {
ClutterTextDirection text_dir; ClutterTextDirection text_dir;
text_dir = clutter_actor_get_text_direction (CLUTTER_ACTOR (container)); text_dir = clutter_actor_get_text_direction (container);
is_rtl = (text_dir == CLUTTER_TEXT_DIRECTION_RTL) ? TRUE : FALSE; is_rtl = (text_dir == CLUTTER_TEXT_DIRECTION_RTL) ? TRUE : FALSE;
} }
else else
is_rtl = FALSE; is_rtl = FALSE;
for (l = (is_rtl) ? g_list_last (children) : children; for (child = (is_rtl) ? clutter_actor_get_last_child (container)
l != NULL; : clutter_actor_get_first_child (container);
l = (is_rtl) ? l->prev : l->next) child != NULL;
child = (is_rtl) ? clutter_actor_get_previous_sibling (child)
: clutter_actor_get_next_sibling (child))
{ {
ClutterActor *child = l->data;
gfloat child_min = 0, child_nat = 0; gfloat child_min = 0, child_nat = 0;
if (!CLUTTER_ACTOR_IS_VISIBLE (child)) if (!CLUTTER_ACTOR_IS_VISIBLE (child))
@ -713,15 +713,10 @@ clutter_box_layout_get_preferred_width (ClutterLayoutManager *layout,
gfloat *natural_width_p) gfloat *natural_width_p)
{ {
ClutterBoxLayout *self = CLUTTER_BOX_LAYOUT (layout); ClutterBoxLayout *self = CLUTTER_BOX_LAYOUT (layout);
GList *children;
children = clutter_container_get_children (container); get_preferred_width (self, CLUTTER_ACTOR (container), for_height,
get_preferred_width (self, container, children, for_height,
min_width_p, min_width_p,
natural_width_p); natural_width_p);
g_list_free (children);
} }
static void static void
@ -732,15 +727,10 @@ clutter_box_layout_get_preferred_height (ClutterLayoutManager *layout,
gfloat *natural_height_p) gfloat *natural_height_p)
{ {
ClutterBoxLayout *self = CLUTTER_BOX_LAYOUT (layout); ClutterBoxLayout *self = CLUTTER_BOX_LAYOUT (layout);
GList *children;
children = clutter_container_get_children (container); get_preferred_height (self, CLUTTER_ACTOR (container), for_width,
get_preferred_height (self, container, children, for_width,
min_height_p, min_height_p,
natural_height_p); natural_height_p);
g_list_free (children);
} }
static void static void
@ -749,16 +739,16 @@ count_expand_children (ClutterLayoutManager *layout,
gint *visible_children, gint *visible_children,
gint *expand_children) gint *expand_children)
{ {
GList *children, *l; ClutterActor *actor, *child;
ClutterActor *child;
actor = CLUTTER_ACTOR (container);
*visible_children = *expand_children = 0; *visible_children = *expand_children = 0;
children = clutter_container_get_children (container); for (child = clutter_actor_get_first_child (actor);
for (l = children; l != NULL; l = l->next) child != NULL;
child = clutter_actor_get_next_sibling (child))
{ {
child = l->data;
if (CLUTTER_ACTOR_IS_VISIBLE (child)) if (CLUTTER_ACTOR_IS_VISIBLE (child))
{ {
ClutterLayoutMeta *meta; ClutterLayoutMeta *meta;
@ -773,7 +763,6 @@ count_expand_children (ClutterLayoutManager *layout,
*expand_children += 1; *expand_children += 1;
} }
} }
g_list_free (children);
} }
struct _ClutterRequestedSize struct _ClutterRequestedSize
@ -899,8 +888,7 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
ClutterAllocationFlags flags) ClutterAllocationFlags flags)
{ {
ClutterBoxLayoutPrivate *priv = CLUTTER_BOX_LAYOUT (layout)->priv; ClutterBoxLayoutPrivate *priv = CLUTTER_BOX_LAYOUT (layout)->priv;
ClutterActor *child; ClutterActor *actor, *child;
GList *children, *l;
gint nvis_children; gint nvis_children;
gint nexpand_children; gint nexpand_children;
gboolean is_rtl; gboolean is_rtl;
@ -927,12 +915,13 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
else else
size = box->x2 - box->x1 - (nvis_children - 1) * priv->spacing; size = box->x2 - box->x1 - (nvis_children - 1) * priv->spacing;
/* Retrieve desired size for visible children. */ actor = CLUTTER_ACTOR (container);
children = clutter_container_get_children (container);
for (i = 0, l = children; l != NULL; l = l->next)
{
child = l->data;
/* Retrieve desired size for visible children. */
for (i = 0, child = clutter_actor_get_first_child (actor);
child != NULL;
child = clutter_actor_get_next_sibling (child))
{
if (!CLUTTER_ACTOR_IS_VISIBLE (child)) if (!CLUTTER_ACTOR_IS_VISIBLE (child))
continue; continue;
@ -972,7 +961,6 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
i++; i++;
} }
g_list_free (children);
if (priv->is_homogeneous) if (priv->is_homogeneous)
{ {
@ -1034,15 +1022,16 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
x = 0.0 + box->x2 - box->x1; x = 0.0 + box->x2 - box->x1;
} }
children = clutter_container_get_children (container); i = clutter_actor_get_n_children (actor);
for (i = g_list_length (children) - 1, l = g_list_last (children); for (child = clutter_actor_get_last_child (actor);
l != NULL; child != NULL;
l = l->prev, i--) child = clutter_actor_get_previous_sibling (child))
{ {
ClutterLayoutMeta *meta; ClutterLayoutMeta *meta;
ClutterBoxChild *box_child; ClutterBoxChild *box_child;
child = l->data; i -= 1;
meta = clutter_layout_manager_get_child_meta (layout, meta = clutter_layout_manager_get_child_meta (layout,
container, container,
child); child);
@ -1146,7 +1135,6 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
&child_allocation, &child_allocation,
flags); flags);
} }
g_list_free (children);
} }
static ClutterAlpha * static ClutterAlpha *