[gtk: 1/2] list-item: Use notify_by_pspec instead of by name




commit 8328bd9f9614b4e16d25c855cc591064f76c9c33
Author: Ivan Molodetskikh <yalterz gmail com>
Date:   Fri May 6 18:05:03 2022 +0300

    list-item: Use notify_by_pspec instead of by name
    
    This is a hot path when scrolling a ColumnView, and
    g_param_spec_pool_lookup () was taking a measurable part in this hot
    path. Instead, notify using pspecs to avoid the name lookup.
    
    Related: https://gitlab.gnome.org/GNOME/gtk/-/issues/3334

 gtk/gtklistitem.c        | 16 ++++++++++++++++
 gtk/gtklistitemprivate.h |  5 +++++
 gtk/gtklistitemwidget.c  |  9 +--------
 3 files changed, 22 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtklistitem.c b/gtk/gtklistitem.c
index b4371b8c93..47fed45058 100644
--- a/gtk/gtklistitem.c
+++ b/gtk/gtklistitem.c
@@ -247,6 +247,22 @@ gtk_list_item_new (void)
   return g_object_new (GTK_TYPE_LIST_ITEM, NULL);
 }
 
+void
+gtk_list_item_do_notify (GtkListItem *list_item,
+                         gboolean notify_item,
+                         gboolean notify_position,
+                         gboolean notify_selected)
+{
+  GObject *object = G_OBJECT (list_item);
+
+  if (notify_item)
+    g_object_notify_by_pspec (object, properties[PROP_ITEM]);
+  if (notify_position)
+    g_object_notify_by_pspec (object, properties[PROP_POSITION]);
+  if (notify_selected)
+    g_object_notify_by_pspec (object, properties[PROP_SELECTED]);
+}
+
 /**
  * gtk_list_item_get_item: (attributes org.gtk.Method.get_property=item)
  * @self: a `GtkListItem`
diff --git a/gtk/gtklistitemprivate.h b/gtk/gtklistitemprivate.h
index d8f8833313..af8cdd4c94 100644
--- a/gtk/gtklistitemprivate.h
+++ b/gtk/gtklistitemprivate.h
@@ -40,6 +40,11 @@ struct _GtkListItem
 
 GtkListItem *   gtk_list_item_new                               (void);
 
+void            gtk_list_item_do_notify                         (GtkListItem *list_item,
+                                                                 gboolean notify_item,
+                                                                 gboolean notify_position,
+                                                                 gboolean notify_selected);
+
 
 G_END_DECLS
 
diff --git a/gtk/gtklistitemwidget.c b/gtk/gtklistitemwidget.c
index 5ef1d357b7..56f807cf70 100644
--- a/gtk/gtklistitemwidget.c
+++ b/gtk/gtklistitemwidget.c
@@ -576,14 +576,7 @@ gtk_list_item_widget_default_update (GtkListItemWidget *self,
     }
 
   if (list_item)
-    {
-      if (notify_item)
-        g_object_notify (G_OBJECT (list_item), "item");
-      if (notify_position)
-        g_object_notify (G_OBJECT (list_item), "position");
-      if (notify_selected)
-        g_object_notify (G_OBJECT (list_item), "selected");
-    }
+    gtk_list_item_do_notify (list_item, notify_item, notify_position, notify_selected);
 }
 
 void


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