[gtk/wip/otte/whatever: 7/15] filterlistmodel: Look at type of change



commit c74201ca87f36630b0d77e2571524c4af5ac8aa0
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 e553a5bb31..1d83ceca89 100644
--- a/gtk/gtkfilterlistmodel.c
+++ b/gtk/gtkfilterlistmodel.c
@@ -483,7 +483,7 @@ gtk_filter_list_model_refilter (GtkFilterListModel *self,
 
     case GTK_FILTER_MATCH_SOME:
       {
-        GtkBitset *old;
+        GtkBitset *old, *pending;
       
         if (self->matches == NULL)
           {
@@ -496,9 +496,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]