diff options
author | Benjamin Otte <otte@redhat.com> | 2022-10-17 19:54:40 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2022-10-17 20:11:27 +0200 |
commit | 5e8b294faf38f9a5e3323c1c983877caee9d6421 (patch) | |
tree | 3bcfd073274032952c03f21f6ba0a864933d763e | |
parent | 6f5d18a9f5c5ce28ed3bed98365967565dfa8b94 (diff) | |
download | gtk+-5e8b294faf38f9a5e3323c1c983877caee9d6421.tar.gz |
singleselection: Be more careful about notifies
We don't want to notify::selected or notify::selected-item if they
didn't change.
This will bring performance benefits on frequently changing lists.
In particular, if lists get filtered or reordered, but the selected item
stays in the list, not doing a notify::selected-item will avoid updates
in connected handlers like GtkDropdown (and its handlers), thereby
avoiding lots of unnecessary updates.
-rw-r--r-- | gtk/gtksingleselection.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/gtk/gtksingleselection.c b/gtk/gtksingleselection.c index fb5c1ad435..7e06575872 100644 --- a/gtk/gtksingleselection.c +++ b/gtk/gtksingleselection.c @@ -200,7 +200,6 @@ gtk_single_selection_items_changed_cb (GListModel *model, { self->selected += added - removed; g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED]); - g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED_ITEM]); } else { @@ -216,7 +215,6 @@ gtk_single_selection_items_changed_cb (GListModel *model, { self->selected = position + i; g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED]); - g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED_ITEM]); } g_object_unref (item); @@ -226,6 +224,8 @@ gtk_single_selection_items_changed_cb (GListModel *model, } if (i == added) { + guint old_selected = self->selected; + /* the item really was deleted */ g_clear_object (&self->selected_item); if (self->autoselect) @@ -266,7 +266,9 @@ gtk_single_selection_items_changed_cb (GListModel *model, g_clear_object (&self->selected_item); self->selected = GTK_INVALID_LIST_POSITION; } - g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED]); + if (old_selected != self->selected) + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED]); + /* the item was deleted above, so this is guaranteed to be new, even if the position didn't change */ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED_ITEM]); } } |