[gtk/wip/otte/filterlistmodel: 6/13] filterlistmodel: Look at type of change



commit 66fa9380b58081799a24369d0d337e745555408e
Author: Benjamin Otte <otte redhat com>
Date:   Tue Jun 30 04:18:59 2020 +0200

    filterlistmodel: Look at type of change
    
    This way we can avoid refiltering most of an already filtered list when
    the change becomes more strict.

 gtk/gtkfilterlistmodel.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkfilterlistmodel.c b/gtk/gtkfilterlistmodel.c
index 9ef3545e85..3f8aedb0b3 100644
--- a/gtk/gtkfilterlistmodel.c
+++ b/gtk/gtkfilterlistmodel.c
@@ -476,7 +476,7 @@ gtk_filter_list_model_refilter (GtkFilterListModel *self,
 
     case GTK_FILTER_MATCH_SOME:
       {
-        GtkBitset *old;
+        GtkBitset *old, *pending;
       
         if (self->matches == NULL)
           {
@@ -489,9 +489,27 @@ gtk_filter_list_model_refilter (GtkFilterListModel *self,
           {
             old = self->matches;
           }
-        self->matches = gtk_bitset_new_empty ();
         self->strictness = new_strictness;
-        gtk_filter_list_model_start_filtering (self, gtk_bitset_new_range (0, g_list_model_get_n_items 
(self->model)));
+        switch (change)
+          {
+          default:
+            g_assert_not_reached ();
+            G_GNUC_FALLTHROUGH;
+          case GTK_FILTER_CHANGE_DIFFERENT:
+            self->matches = gtk_bitset_new_empty ();
+            pending = gtk_bitset_new_range (0, g_list_model_get_n_items (self->model));
+            break;
+          case GTK_FILTER_CHANGE_LESS_STRICT:
+            self->matches = gtk_bitset_copy (old);
+            pending = gtk_bitset_new_range (0, g_list_model_get_n_items (self->model));
+            gtk_bitset_subtract (pending, self->matches);
+            break;
+          case GTK_FILTER_CHANGE_MORE_STRICT:
+            self->matches = gtk_bitset_new_empty ();
+            pending = gtk_bitset_copy (old);
+            break;
+          }
+        gtk_filter_list_model_start_filtering (self, pending);
 
         gtk_filter_list_model_emit_items_changed_for_changes (self, old);
       }


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