summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.van.berkom@gmail.com>2011-11-17 19:18:46 -0500
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2011-11-17 19:18:46 -0500
commit9e4376415a4e25edd81c7c0fed6101cd560a4215 (patch)
tree7729e679cc55045e381c33f0b3c79d158861acd2
parent5284fe2e57aa004139b38ca13972e50652cffa29 (diff)
downloadglade-9e4376415a4e25edd81c7c0fed6101cd560a4215.tar.gz
2011-11-17 Fredy Paquet <fpa@opag.ch>
* plugins/gtk+/glade-gtk.c: Improved performance of modifying GtkTable contents, shows specifically when loading files containing large tables. Bug 663516
-rw-r--r--ChangeLog7
-rw-r--r--plugins/gtk+/glade-gtk.c87
2 files changed, 76 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 8ee42cdf..0cecc0aa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-11-17 Fredy Paquet <fpa@opag.ch>
+
+ * plugins/gtk+/glade-gtk.c: Improved performance of modifying GtkTable
+ contents, shows specifically when loading files containing large tables.
+
+ Bug 663516
+
2011-10-11 Benjamin Otte <otte@redhat.com>
* gladeui/glade-editor-property.c:
diff --git a/plugins/gtk+/glade-gtk.c b/plugins/gtk+/glade-gtk.c
index 8903fa92..b55df6e7 100644
--- a/plugins/gtk+/glade-gtk.c
+++ b/plugins/gtk+/glade-gtk.c
@@ -2779,36 +2779,87 @@ glade_gtk_table_widget_exceeds_bounds (GtkTable *table, gint n_rows, gint n_cols
return ret;
}
+#define TABLE_OCCUPIED(occmap, n_columns, col, row) \
+ (occmap)[row * n_columns + col]
+
+static void
+glade_gtk_table_build_occupation_maps(GtkTable *table, guint n_columns, guint n_rows,
+ gchar **child_map, gpointer **placeholder_map)
+{
+ guint i, j;
+ GList *list, *children = gtk_container_get_children (GTK_CONTAINER (table));
+
+ *child_map = g_malloc0(n_columns * n_rows * sizeof(gchar)); /* gchar is smaller than gboolean */
+ *placeholder_map = g_malloc0(n_columns * n_rows * sizeof(gpointer));
+
+ for (list = children; list && list->data; list = list->next)
+ {
+ GtkTableChild child;
+
+ glade_gtk_table_get_child_attachments (GTK_WIDGET (table),
+ GTK_WIDGET (list->data), &child);
+
+ if (GLADE_IS_PLACEHOLDER(list->data))
+ {
+ /* assumption: placeholders are always attached to exactly 1 cell */
+ TABLE_OCCUPIED(*placeholder_map, n_columns, child.left_attach, child.top_attach) = list->data;
+ }
+ else
+ {
+ for (i = child.left_attach; i < child.right_attach && i < n_columns; i++)
+ {
+ for (j = child.top_attach; j < child.bottom_attach && j < n_rows; j++)
+ {
+ TABLE_OCCUPIED(*child_map, n_columns, i, j) = 1;
+ }
+ }
+ }
+ }
+ g_list_free (children);
+}
+
static void
glade_gtk_table_refresh_placeholders (GtkTable *table)
{
- GList *list, *children;
- guint n_columns, n_rows;
- gint i, j;
+ guint n_columns, n_rows, i, j;
+ gchar *child_map;
+ gpointer *placeholder_map;
g_object_get (table,
"n-columns", &n_columns,
"n-rows", &n_rows,
NULL);
- children = gtk_container_get_children (GTK_CONTAINER (table));
+ glade_gtk_table_build_occupation_maps(table, n_columns, n_rows,
+ &child_map, &placeholder_map);
- for (list = children; list && list->data; list = list->next)
+ for (i = 0; i < n_columns; i++)
{
- if (GLADE_IS_PLACEHOLDER (list->data))
- gtk_container_remove (GTK_CONTAINER (table),
- GTK_WIDGET (list->data));
- }
- g_list_free (children);
+ for (j = 0; j < n_rows; j++)
+ {
+ gpointer placeholder = TABLE_OCCUPIED(placeholder_map, n_columns, i, j);
- for (i = 0; i < n_columns; i++)
- for (j = 0; j < n_rows; j++)
- if (glade_gtk_table_has_child (table, i, j) == FALSE)
- {
- gtk_table_attach_defaults (table,
- glade_placeholder_new (),
- i, i + 1, j, j + 1);
- }
+ if (TABLE_OCCUPIED(child_map, n_columns, i, j))
+ {
+ if (placeholder)
+ {
+ gtk_container_remove (GTK_CONTAINER (table),
+ GTK_WIDGET (placeholder));
+ }
+ }
+ else
+ {
+ if (!placeholder)
+ {
+ gtk_table_attach_defaults (table,
+ glade_placeholder_new (),
+ i, i + 1, j, j + 1);
+ }
+ }
+ }
+ }
+ g_free(child_map);
+ g_free(placeholder_map);
gtk_container_check_resize (GTK_CONTAINER (table));
}