[sysprof] Eliminate as many signal emissions as we can from footreestore.c
- From: Søren Sandmann Pedersen <ssp src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [sysprof] Eliminate as many signal emissions as we can from footreestore.c
- Date: Mon, 14 Sep 2009 09:06:56 +0000 (UTC)
commit 6849c1472d415ecc3612b80c5301458441acee5b
Author: Søren Sandmann Pedersen <ssp redhat com>
Date: Mon Aug 17 05:45:46 2009 -0400
Eliminate as many signal emissions as we can from footreestore.c
footreestore.c | 59 +++++++++++++++++++++++++++++++++++-------------------
footreestore.h | 6 +++++
treeviewutils.c | 30 ++++++++++++++++-----------
3 files changed, 62 insertions(+), 33 deletions(-)
---
diff --git a/footreestore.c b/footreestore.c
index 1629e6c..e2ab611 100644
--- a/footreestore.c
+++ b/footreestore.c
@@ -233,6 +233,11 @@ foo_tree_store_init (FooTreeStore *tree_store)
tree_store->sort_list = NULL;
tree_store->sort_column_id = GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID;
tree_store->columns_dirty = FALSE;
+
+ tree_store->row_changed_id = g_signal_lookup ("row_changed", GTK_TYPE_TREE_MODEL);
+ tree_store->row_inserted_id = g_signal_lookup ("row_inserted", GTK_TYPE_TREE_MODEL);
+ tree_store->row_has_child_toggled_id = g_signal_lookup ("row_has_child_toggled", GTK_TYPE_TREE_MODEL);
+ tree_store->rows_reordered_id = g_signal_lookup ("rows_reordered", GTK_TYPE_TREE_MODEL);
}
/**
@@ -1059,11 +1064,13 @@ foo_tree_store_set_valist (FooTreeStore *tree_store,
if (emit_signal)
{
- GtkTreePath *path;
-
- path = foo_tree_store_get_path (GTK_TREE_MODEL (tree_store), iter);
- gtk_tree_model_row_changed (GTK_TREE_MODEL (tree_store), path, iter);
- gtk_tree_path_free (path);
+ if (g_signal_has_handler_pending (tree_store, tree_store->row_changed_id, 0, FALSE))
+ {
+ GtkTreePath *path;
+ path = foo_tree_store_get_path (GTK_TREE_MODEL (tree_store), iter);
+ gtk_tree_model_row_changed (GTK_TREE_MODEL (tree_store), path, iter);
+ gtk_tree_path_free (path);
+ }
}
}
@@ -1182,7 +1189,6 @@ foo_tree_store_insert (FooTreeStore *tree_store,
GtkTreeIter *parent,
gint position)
{
- GtkTreePath *path;
GNode *parent_node;
GNode *new_node;
@@ -1204,20 +1210,26 @@ foo_tree_store_insert (FooTreeStore *tree_store,
iter->user_data = new_node;
g_node_insert (parent_node, position, new_node);
- path = foo_tree_store_get_path (GTK_TREE_MODEL (tree_store), iter);
- gtk_tree_model_row_inserted (GTK_TREE_MODEL (tree_store), path, iter);
-
- if (parent_node != tree_store->root)
+ if (g_signal_has_handler_pending (tree_store, tree_store->row_inserted_id, 0, FALSE) ||
+ g_signal_has_handler_pending (tree_store, tree_store->row_has_child_toggled_id, 0, FALSE))
{
- if (new_node->prev == NULL && new_node->next == NULL)
- {
- gtk_tree_path_up (path);
- gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (tree_store), path, parent);
- }
+ GtkTreePath *path;
+
+ path = foo_tree_store_get_path (GTK_TREE_MODEL (tree_store), iter);
+ gtk_tree_model_row_inserted (GTK_TREE_MODEL (tree_store), path, iter);
+
+ if (parent_node != tree_store->root)
+ {
+ if (new_node->prev == NULL && new_node->next == NULL)
+ {
+ gtk_tree_path_up (path);
+ gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (tree_store), path, parent);
+ }
+ }
+
+ gtk_tree_path_free (path);
}
- gtk_tree_path_free (path);
-
validate_tree ((FooTreeStore*)tree_store);
}
@@ -2850,10 +2862,15 @@ foo_tree_store_sort_helper (FooTreeStore *tree_store,
iter.stamp = tree_store->stamp;
iter.user_data = parent;
- path = foo_tree_store_get_path (GTK_TREE_MODEL (tree_store), &iter);
- gtk_tree_model_rows_reordered (GTK_TREE_MODEL (tree_store),
- path, &iter, new_order);
- gtk_tree_path_free (path);
+
+ if (g_signal_has_handler_pending (tree_store, tree_store->row_inserted_id, 0, FALSE))
+ {
+ path = foo_tree_store_get_path (GTK_TREE_MODEL (tree_store), &iter);
+ gtk_tree_model_rows_reordered (GTK_TREE_MODEL (tree_store),
+ path, &iter, new_order);
+ gtk_tree_path_free (path);
+ }
+
g_free (new_order);
g_array_free (sort_array, TRUE);
diff --git a/footreestore.h b/footreestore.h
index a79e5da..bac0312 100644
--- a/footreestore.h
+++ b/footreestore.h
@@ -56,6 +56,12 @@ struct _FooTreeStore
GtkTreeIterCompareFunc GSEAL (default_sort_func);
gpointer GSEAL (default_sort_data);
GDestroyNotify GSEAL (default_sort_destroy);
+
+ guint row_changed_id;
+ guint row_inserted_id;
+ guint row_has_child_toggled_id;
+ guint rows_reordered_id;
+
guint GSEAL (columns_dirty) : 1;
};
diff --git a/treeviewutils.c b/treeviewutils.c
index 99b8807..7511daf 100644
--- a/treeviewutils.c
+++ b/treeviewutils.c
@@ -256,26 +256,32 @@ tree_view_set_model_with_default_sort (GtkTreeView *view,
int model_column,
GtkSortType default_sort)
{
- gboolean was_sorted = FALSE;
- int old_column;
- GtkSortType old_type;
+ int column;
+ GtkSortType type;
GtkTreeSortable *old_model;
GtkAdjustment *adjustment;
old_model = GTK_TREE_SORTABLE (gtk_tree_view_get_model (view));
- if (old_model)
+ if (!(old_model && gtk_tree_sortable_get_sort_column_id (
+ GTK_TREE_SORTABLE (old_model), &column, &type)))
{
- was_sorted = gtk_tree_sortable_get_sort_column_id (
- GTK_TREE_SORTABLE (old_model), &old_column, &old_type);
+ column = model_column;
+ type = default_sort;
}
-
+
+ /* Setting the sort column here prevents the "rows_reordered"
+ * signal from being emitted when the model is attached to
+ * a treeview. This is desirable because at that point there
+ * is a handler attached, which means the signal will actually
+ * be emitted.
+ */
+ gtk_tree_sortable_set_sort_column_id (
+ GTK_TREE_SORTABLE (model), column, type);
+
gtk_tree_view_set_model (view, model);
-
- if (was_sorted)
- tree_view_set_sort_column (view, old_column, old_type);
- else
- tree_view_set_sort_column (view, model_column, default_sort);
+
+ tree_view_set_sort_column (view, column, type);
/* Workaround for GTK+ crack, see bug 405625 */
adjustment = gtk_tree_view_get_vadjustment (view);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]