summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <sandmann@daimi.au.dk>2010-11-10 04:42:59 -0500
committerSøren Sandmann Pedersen <sandmann@daimi.au.dk>2011-06-29 02:48:21 -0400
commit1d22fff69fb539119fcf26a31a2f9147307e0b8f (patch)
tree320d87b43c4bb66c86693a32bf6083a742c38c03
parentca77ee2a91f239ea1d7d6a471fd130320b05ea08 (diff)
Apply yet another workaround for GTK+ performance issues.
Sorting ends up emitting rows_reordered a lot, which requires building a bunch of GtkTreePaths, which is O(n^2) in the number of indices. By temporarily unsetting the model, we can avoid emitting those signals. To avoid an ugly flash, we also temporarily disable updating the tree view window. See https://bugzilla.gnome.org/show_bug.cgi?id=634491
-rw-r--r--treeviewutils.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/treeviewutils.c b/treeviewutils.c
index af82da8..8c655af 100644
--- a/treeviewutils.c
+++ b/treeviewutils.c
@@ -88,6 +88,7 @@ tree_view_set_sort_column (GtkTreeView *view,
GtkTreeSortable *sortable;
GtkTreeViewColumn *column = find_column_by_model_column (view, model_column);
SortInfo *info = get_sort_info (column);
+ GdkWindow *window;
/* For each column in the view, unset the sort indicator */
columns = gtk_tree_view_get_columns (view);
@@ -98,16 +99,35 @@ tree_view_set_sort_column (GtkTreeView *view,
gtk_tree_view_column_set_sort_indicator (col, FALSE);
}
- /* Set the sort indicator for this column */
- gtk_tree_view_column_set_sort_indicator (column, TRUE);
- gtk_tree_view_column_set_sort_order (column, sort_type);
-
/* And sort the column */
sortable = GTK_TREE_SORTABLE (gtk_tree_view_get_model (view));
+
+ /* Sorting ends up emitting rows_reordered a lot, which requires building
+ * a bunch of GtkTreePaths, which is O(n^2) in the number of indices.
+ *
+ * By temporarily unsetting the model, we can avoid emitting those
+ * signals. To avoid an ugly flash, we also temporarily disable updating
+ * the tree view window.
+ *
+ * See https://bugzilla.gnome.org/show_bug.cgi?id=634491
+ */
+ gdk_window_freeze_updates (gtk_widget_get_window (GTK_WIDGET (view)));
+
+ g_object_ref (sortable);
+ gtk_tree_view_set_model (view, NULL);
gtk_tree_sortable_set_sort_column_id (sortable,
info->model_column,
sort_type);
+
+ gtk_tree_view_set_model (view, GTK_TREE_MODEL (sortable));
+ g_object_unref (GTK_TREE_MODEL (sortable));
+
+ /* Set the sort indicator for this column */
+ gtk_tree_view_column_set_sort_indicator (column, TRUE);
+ gtk_tree_view_column_set_sort_order (column, sort_type);
+
+ gdk_window_thaw_updates (gtk_widget_get_window (GTK_WIDGET (view)));
}
static void