From 3894f04d0eb03dbba2814370c76402361345b448 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 6 May 2022 18:05:03 +0300 Subject: [PATCH] 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 -- 2.30.2