[gtk+/native-layout] Fixed gtk_cell_view_allocate() to allocate a fixed array size instead of using a growing dynamic GAr
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/native-layout] Fixed gtk_cell_view_allocate() to allocate a fixed array size instead of using a growing dynamic GAr
- Date: Wed, 18 Aug 2010 23:10:09 +0000 (UTC)
commit 4a2905c34b02ac52edf8c5f87abd5e5c58059eee
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Wed Aug 18 19:11:01 2010 -0400
Fixed gtk_cell_view_allocate() to allocate a fixed array size instead of using
a growing dynamic GArray in a loop.
gtk/gtkcellview.c | 47 ++++++++++++++++++++++++++++-------------------
1 files changed, 28 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkcellview.c b/gtk/gtkcellview.c
index 12b4efd..bf15a3e 100644
--- a/gtk/gtkcellview.c
+++ b/gtk/gtkcellview.c
@@ -336,11 +336,10 @@ static void
gtk_cell_view_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
- GtkCellView *cellview;
+ GtkCellView *cellview;
GtkRequestedSize *sizes;
- GArray *array;
GList *list;
- gint nexpand_cells = 0;
+ gint n_visible_cells, n_expand_cells;
gint avail_width = 0;
gint extra_per_cell, extra_extra, i;
gboolean first_cell = TRUE;
@@ -351,41 +350,49 @@ gtk_cell_view_size_allocate (GtkWidget *widget,
avail_width = allocation->width;
- array = g_array_new (0, TRUE, sizeof (GtkRequestedSize));
+ /* Count visible/expand children */
+ for (n_visible_cells = 0, n_expand_cells = 0, list = cellview->priv->cell_list;
+ list; list = list->next)
+ {
+ GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)list->data;
+
+ n_visible_cells++;
+
+ if (info->expand)
+ n_expand_cells++;
+ }
+
+ sizes = g_new0 (GtkRequestedSize, n_visible_cells);
/* checking how much extra space we have */
- for (list = cellview->priv->cell_list; list; list = list->next)
+ for (i = 0, list = cellview->priv->cell_list; list; list = list->next)
{
GtkCellViewCellInfo *info = (GtkCellViewCellInfo *)list->data;
- GtkRequestedSize requested;
if (!gtk_cell_renderer_get_visible (info->cell))
continue;
- if (info->expand)
- nexpand_cells++;
-
- requested.data = info;
- requested.minimum_size = info->requested_width;
- requested.natural_size = info->natural_width;
- g_array_append_val (array, requested);
+ sizes[i].data = info;
+ sizes[i].minimum_size = info->requested_width;
+ sizes[i].natural_size = info->natural_width;
if (!first_cell)
avail_width -= cellview->priv->spacing;
- avail_width -= requested.minimum_size;
+ avail_width -= sizes[i].minimum_size;
first_cell = FALSE;
+
+ i++;
}
- sizes = (GtkRequestedSize *)array->data;
- avail_width = gtk_distribute_natural_allocation (MAX (0, avail_width), array->len, sizes);
+ avail_width = gtk_distribute_natural_allocation (MAX (0, avail_width), n_visible_cells, sizes);
/* Deal with any expand space... */
- if (nexpand_cells > 0)
+ if (n_expand_cells > 0)
{
- extra_per_cell = avail_width / nexpand_cells;
- extra_extra = avail_width % nexpand_cells;
+ extra_per_cell = avail_width / n_expand_cells;
+ extra_extra = avail_width % n_expand_cells;
}
else
/* Everything just left-aligned if no cells expand */
@@ -414,6 +421,8 @@ gtk_cell_view_size_allocate (GtkWidget *widget,
/* increment index into sizes for visible children */
i++;
}
+
+ g_free (sizes);
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]