[gtk+] gdkwindow: avoid multiple walking of children list



commit 1c8760c5fafa4d55eef9b31166e2095b88b06b46
Author: Christian Hergert <christian hergert me>
Date:   Mon Sep 14 12:25:44 2015 -0700

    gdkwindow: avoid multiple walking of children list
    
    This counts the number of children and fetches the last GList
    node at the same time.

 gdk/gdkwindow.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 3298b8a..89ed898 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -3545,6 +3545,7 @@ _gdk_window_process_updates_recurse_helper (GdkWindow *window,
   GdkWindow **free_children = NULL;
   int i, n_children;
   GList *l;
+  GList *last_link;
 
   if (window->destroyed)
     return;
@@ -3587,14 +3588,22 @@ _gdk_window_process_updates_recurse_helper (GdkWindow *window,
       _gdk_event_emit (&event);
     }
 
-  n_children = g_list_length (window->children);
+  n_children = 0;
+  last_link = NULL;
+  /* Count n_children and fetch bottommost at same time */
+  for (l = window->children; l != NULL; l = l->next)
+    {
+      last_link = l;
+      n_children++;
+    }
+
   children = g_newa (GdkWindow *, n_children);
   if (children == NULL)
     children = free_children = g_new (GdkWindow *, n_children);
 
   n_children = 0;
   /* Iterate over children, starting at bottommost */
-  for (l = g_list_last (window->children); l != NULL; l = l->prev)
+  for (l = last_link; l != NULL; l = l->prev)
     {
       child = l->data;
 


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