[devhelp] KeywordModel: do not send the GtkTreeModel signals



commit c1b83d74c7e2f8f7eb79c81c267fd370708da433
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jan 20 18:04:18 2018 +0100

    KeywordModel: do not send the GtkTreeModel signals
    
    DhSidebar already disconnects the model from the view when calling
    dh_keyword_model_filter(), so sending the signals was useless.

 src/dh-keyword-model.c |   99 +++++------------------------------------------
 1 files changed, 11 insertions(+), 88 deletions(-)
---
diff --git a/src/dh-keyword-model.c b/src/dh-keyword-model.c
index 2b0a5ab..d46646c 100644
--- a/src/dh-keyword-model.c
+++ b/src/dh-keyword-model.c
@@ -606,88 +606,6 @@ keyword_model_search (DhKeywordModel   *model,
         return out;
 }
 
-static void
-set_links (DhKeywordModel *model,
-           GQueue         *new_links)
-{
-        DhKeywordModelPrivate *priv;
-        gint old_length;
-        gint new_length;
-        gint row_num;
-        GList *node;
-        GtkTreePath *path;
-
-        priv = dh_keyword_model_get_instance_private (model);
-
-        old_length = priv->links.length;
-        new_length = new_links->length;
-
-        g_queue_clear (&priv->links);
-        dh_util_queue_concat (&priv->links, new_links);
-        new_links = NULL;
-
-        /* Update model: common rows */
-        row_num = 0;
-        node = priv->links.head;
-        path = gtk_tree_path_new_first ();
-
-        while (row_num < MIN (old_length, new_length)) {
-                GtkTreeIter iter;
-
-                g_assert (node != NULL);
-
-                iter.stamp = priv->stamp;
-                iter.user_data = node;
-
-                gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
-
-                row_num++;
-                node = node->next;
-                gtk_tree_path_next (path);
-        }
-
-        gtk_tree_path_free (path);
-
-        /* Insert new rows */
-        if (old_length < new_length) {
-                row_num = old_length;
-                g_assert_cmpint (g_queue_link_index (&priv->links, node), ==, row_num);
-                path = gtk_tree_path_new_from_indices (row_num, -1);
-
-                while (row_num < new_length) {
-                        GtkTreeIter iter;
-
-                        g_assert (node != NULL);
-
-                        iter.stamp = priv->stamp;
-                        iter.user_data = node;
-
-                        gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter);
-
-                        row_num++;
-                        node = node->next;
-                        gtk_tree_path_next (path);
-                }
-
-                gtk_tree_path_free (path);
-        }
-
-        /* Delete old rows */
-        else if (old_length > new_length) {
-                row_num = old_length - 1;
-                path = gtk_tree_path_new_from_indices (row_num, -1);
-
-                while (row_num >= new_length) {
-                        gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
-
-                        row_num--;
-                        gtk_tree_path_prev (path);
-                }
-
-                gtk_tree_path_free (path);
-        }
-}
-
 /**
  * dh_keyword_model_filter:
  * @model: a #DhKeywordModel.
@@ -699,6 +617,12 @@ set_links (DhKeywordModel *model,
  * @search_string, and fills the @model with that list (erasing the previous
  * content).
  *
+ * Attention, when calling this function the @model needs to be disconnected
+ * from the #GtkTreeView, because the #GtkTreeModel signals are not emitted, to
+ * improve the performances (sending a lot of signals is slow) and have a
+ * simpler implementation. The previous row selection is anyway no longer
+ * relevant.
+ *
  * Note that there is a maximum number of matches (configured internally). When
  * the maximum is reached the search is stopped, to avoid blocking the GUI
  * (since this function runs synchronously) if the @search_string contains for
@@ -717,7 +641,7 @@ dh_keyword_model_filter (DhKeywordModel *model,
 {
         DhKeywordModelPrivate *priv;
         DhSearchContext *search_context;
-        GQueue *new_list = NULL;
+        GQueue *new_links = NULL;
         DhLink *exact_link = NULL;
 
         g_return_val_if_fail (DH_IS_KEYWORD_MODEL (model), NULL);
@@ -741,13 +665,12 @@ dh_keyword_model_filter (DhKeywordModel *model,
                 else
                         priv->current_book_id = g_strdup (current_book_id);
 
-                new_list = keyword_model_search (model, search_context, &exact_link);
-        } else {
-                new_list = g_queue_new ();
+                new_links = keyword_model_search (model, search_context, &exact_link);
         }
 
-        set_links (model, new_list);
-        new_list = NULL;
+        g_queue_clear (&priv->links);
+        dh_util_queue_concat (&priv->links, new_links);
+        new_links = NULL;
 
         _dh_search_context_free (search_context);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]