[gtk+/gtk-2-24] Make computing and setting the visibility/filters atomic operations
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-2-24] Make computing and setting the visibility/filters atomic operations
- Date: Thu, 10 Mar 2016 21:33:15 +0000 (UTC)
commit 5c78a27a8b43ff192ae3860ea3ec81b5701ee484
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Jul 11 16:32:52 2012 -0500
Make computing and setting the visibility/filters atomic operations
This way we remove paired function calls (compute/set pairs), and also make
it possible to avoid computing a filter twice, as setting the visibility
depends on filteredness.
Signed-off-by: Federico Mena Quintero <federico gnome org>
gtk/gtkfilesystemmodel.c | 53 ++++++++++++++++++++++-----------------------
1 files changed, 26 insertions(+), 27 deletions(-)
---
diff --git a/gtk/gtkfilesystemmodel.c b/gtk/gtkfilesystemmodel.c
index bf578ae..40eecfd 100644
--- a/gtk/gtkfilesystemmodel.c
+++ b/gtk/gtkfilesystemmodel.c
@@ -310,18 +310,16 @@ emit_row_deleted_for_row (GtkFileSystemModel *model, guint row)
}
static void
-node_set_filtered_out (GtkFileSystemModel *model, guint id, gboolean filtered_out)
+node_set_visible_and_filtered_out (GtkFileSystemModel *model, guint id, gboolean visible, gboolean
filtered_out)
{
FileModelNode *node = get_node (model, id);
- node->filtered_out = filtered_out;
-}
+ /* Filteredness */
-static void
-node_set_visible (GtkFileSystemModel *model, guint id, gboolean visible)
-{
- FileModelNode *node = get_node (model, id);
+ node->filtered_out = filtered_out;
+ /* Visibility */
+
if (node->visible == visible ||
node->frozen_add)
return;
@@ -412,7 +410,7 @@ node_should_be_filtered_out (GtkFileSystemModel *model, guint id)
}
static gboolean
-node_should_be_visible (GtkFileSystemModel *model, guint id)
+node_should_be_visible (GtkFileSystemModel *model, guint id, gboolean filtered_out)
{
FileModelNode *node = get_node (model, id);
gboolean result;
@@ -438,11 +436,23 @@ node_should_be_visible (GtkFileSystemModel *model, guint id)
return FALSE;
}
- result = !node_should_be_filtered_out (model, id);
+ result = !filtered_out;
return result;
}
+static void
+node_compute_visibility_and_filters (GtkFileSystemModel *model, guint id)
+{
+ gboolean filtered_out;
+ gboolean visible;
+
+ filtered_out = node_should_be_filtered_out (model, id);
+ visible = node_should_be_visible (model, id, filtered_out);
+
+ node_set_visible_and_filtered_out (model, id, visible, filtered_out);
+}
+
/*** GtkTreeModel ***/
static GtkTreeModelFlags
@@ -1425,10 +1435,7 @@ gtk_file_system_model_refilter_all (GtkFileSystemModel *model)
/* start at index 1, don't change the editable */
for (i = 1; i < model->files->len; i++)
- {
- node_set_filtered_out (model, i, node_should_be_filtered_out (model, i));
- node_set_visible (model, i, node_should_be_visible (model, i));
- }
+ node_compute_visibility_and_filters (model, i);
model->filter_on_thaw = FALSE;
_gtk_file_system_model_thaw_updates (model);
@@ -1796,12 +1803,8 @@ add_file (GtkFileSystemModel *model,
g_slice_free1 (model->node_size, node);
if (!model->frozen)
- {
- node_set_filtered_out (model, model->files->len -1,
- node_should_be_filtered_out (model, model->files->len - 1));
- node_set_visible (model, model->files->len -1,
- node_should_be_visible (model, model->files->len - 1));
- }
+ node_compute_visibility_and_filters (model, model->files->len -1);
+
gtk_file_system_model_sort_node (model, model->files->len -1);
}
@@ -1829,8 +1832,7 @@ remove_file (GtkFileSystemModel *model,
return;
node = get_node (model, id);
- node_set_visible (model, id, FALSE);
- node_set_filtered_out (model, id, FALSE);
+ node_set_visible_and_filtered_out (model, id, FALSE, FALSE);
g_hash_table_remove (model->file_lookup, file);
g_object_unref (node->file);
@@ -1941,8 +1943,7 @@ _gtk_file_system_model_add_editable (GtkFileSystemModel *model, GtkTreeIter *ite
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
g_return_if_fail (!get_node (model, 0)->visible);
- node_set_visible (model, 0, TRUE);
- node_set_filtered_out (model, 0, FALSE);
+ node_set_visible_and_filtered_out (model, 0, TRUE, FALSE);
ITER_INIT_FROM_INDEX (model, iter, 0);
}
@@ -1960,8 +1961,7 @@ _gtk_file_system_model_remove_editable (GtkFileSystemModel *model)
g_return_if_fail (GTK_IS_FILE_SYSTEM_MODEL (model));
g_return_if_fail (get_node (model, 0)->visible);
- node_set_visible (model, 0, FALSE);
- node_set_filtered_out (model, 0, FALSE);
+ node_set_visible_and_filtered_out (model, 0, FALSE, FALSE);
}
/**
@@ -2018,8 +2018,7 @@ _gtk_file_system_model_thaw_updates (GtkFileSystemModel *model)
if (!node->frozen_add)
continue;
node->frozen_add = FALSE;
- node_set_visible (model, i, node_should_be_visible (model, i));
- node_set_filtered_out (model, i, node_should_be_filtered_out (model, i));
+ node_compute_visibility_and_filters (model, i);
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]