[gtk/faster-listview-scrolling] listitemwidget: Avoid some unnecessary work




commit 3307b8ce88ecf1c86249c984ad13122f0a90b7c0
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri May 6 21:36:22 2022 -0400

    listitemwidget: Avoid some unnecessary work
    
    Only update widget and accessible state if the
    selected property actually changed.

 gtk/gtklistitemwidget.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtklistitemwidget.c b/gtk/gtklistitemwidget.c
index 56f807cf70..959d56fb4d 100644
--- a/gtk/gtklistitemwidget.c
+++ b/gtk/gtklistitemwidget.c
@@ -485,20 +485,27 @@ gtk_list_item_widget_update (GtkListItemWidget *self,
                              gboolean           selected)
 {
   GtkListItemWidgetPrivate *priv = gtk_list_item_widget_get_instance_private (self);
+  gboolean was_selected;
+
+  was_selected = priv->selected;
 
   if (priv->list_item)
     gtk_list_item_factory_update (priv->factory, self, position, item, selected);
   else
     gtk_list_item_widget_default_update (self, NULL, position, item, selected);
 
-  if (selected)
-    gtk_widget_set_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED, FALSE);
-  else
-    gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED);
-
-  gtk_accessible_update_state (GTK_ACCESSIBLE (self),
-                               GTK_ACCESSIBLE_STATE_SELECTED, selected,
-                               -1);
+  /* don't look at selected variable, it's not reentrancy safe */
+  if (was_selected != priv->selected)
+    {
+      if (priv->selected)
+        gtk_widget_set_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED, FALSE);
+      else
+        gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED);
+
+      gtk_accessible_update_state (GTK_ACCESSIBLE (self),
+                                   GTK_ACCESSIBLE_STATE_SELECTED, priv->selected,
+                                   -1);
+    }
 }
 
 void
@@ -559,7 +566,7 @@ gtk_list_item_widget_default_update (GtkListItemWidget *self,
   GtkListItemWidgetPrivate *priv = gtk_list_item_widget_get_instance_private (self);
 
   /* FIXME: It's kinda evil to notify external objects from here... */
-  
+
   if (g_set_object (&priv->item, item))
     notify_item = TRUE;
 


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