[gtk] Avoid calling g_list_model_get_n_items() all the time



commit 0b13e68bcaee182d09a8fe5f24e238c3461f1cfe
Author: Timm Bäder <mail baedert org>
Date:   Sun Jun 7 13:11:33 2020 +0200

    Avoid calling g_list_model_get_n_items() all the time
    
    These are used in hot paths, e.g. widget construction.

 gtk/gtkshortcutcontroller.c | 4 ++--
 gtk/gtkwidget.c             | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkshortcutcontroller.c b/gtk/gtkshortcutcontroller.c
index b11ea5da76..d90a181428 100644
--- a/gtk/gtkshortcutcontroller.c
+++ b/gtk/gtkshortcutcontroller.c
@@ -464,11 +464,11 @@ gtk_shortcut_controller_set_widget (GtkEventController *controller,
                                     GtkWidget          *widget)
 {
   GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (controller);
-  int i;
+  guint i, p;
 
   GTK_EVENT_CONTROLLER_CLASS (gtk_shortcut_controller_parent_class)->set_widget (controller, widget);
 
-  for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (controller)); i++)
+  for (i = 0, p = g_list_model_get_n_items (G_LIST_MODEL (controller)); i < p; i++)
     {
       GtkShortcut *shortcut = g_list_model_get_item (G_LIST_MODEL (controller), i);
       update_accel (shortcut, widget, TRUE);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 483b99eefc..cee8bbb1cd 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -771,10 +771,10 @@ gtk_widget_base_class_init (gpointer g_class)
   else
     {
       GListModel *parent_shortcuts = G_LIST_MODEL (priv->shortcuts);
-      guint i;
+      guint i, p;
 
       priv->shortcuts = g_list_store_new (GTK_TYPE_SHORTCUT);
-      for (i = 0; i < g_list_model_get_n_items (parent_shortcuts); i++)
+      for (i = 0, p = g_list_model_get_n_items (parent_shortcuts); i < p; i++)
         {
           GtkShortcut *shortcut = g_list_model_get_item (parent_shortcuts, i);
           g_list_store_append (priv->shortcuts, shortcut);


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