[gtk/wip/baedert/some-api: 6/7] window: Don't allocate GLists when changing cursors



commit cc56dca251a7013da5083e7a0c7e64866ed637fd
Author: Timm Bäder <mail baedert org>
Date:   Tue Dec 25 12:02:11 2018 +0100

    window: Don't allocate GLists when changing cursors
    
    We do this all the time when moving the cursor and we can now do it
    without the GList allocations.

 gtk/gtkwindow.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 339b0e6f89..85af7b29f6 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -11260,39 +11260,45 @@ update_cursor (GtkWindow *toplevel,
                GtkWidget *target)
 {
   GdkCursor *cursor = NULL;
-  GList *widgets = NULL, *l;
+  GtkWidget **widgets;
+  int n_widgets = 0;
+  int i;
 
   if (grab_widget && !gtk_widget_is_ancestor (target, grab_widget))
     {
       /* Outside the grab widget, cursor stays to whatever the grab
        * widget says.
        */
-      widgets = g_list_prepend (widgets, grab_widget);
+      widgets = g_alloca (sizeof (*widgets));
+      widgets[0] = grab_widget;
+      n_widgets = 1;
     }
   else
     {
       /* Inside the grab widget or in absence of grabs, allow walking
        * up the hierarchy to find out the cursor.
        */
+      widgets = g_alloca (sizeof (*widgets) * gtk_widget_get_depth (target));
+
       while (target)
         {
-          widgets = g_list_prepend (widgets, target);
+          widgets[n_widgets] = target;
+          n_widgets ++;
           if (grab_widget && target == grab_widget)
             break;
           target = _gtk_widget_get_parent (target);
         }
     }
 
-  for (l = g_list_last (widgets); l; l = l->prev)
+  for (i = 0; i < n_widgets; i ++)
     {
-      cursor = gtk_widget_get_cursor (l->data);
+      cursor = gtk_widget_get_cursor (widgets[i]);
       if (cursor)
         break;
     }
 
   gdk_surface_set_device_cursor (gtk_widget_get_surface (GTK_WIDGET (toplevel)),
-                                device, cursor);
-  g_list_free (widgets);
+                                 device, cursor);
 }
 
 void


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