From 1c8760c5fafa4d55eef9b31166e2095b88b06b46 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Mon, 14 Sep 2015 12:25:44 -0700 Subject: [PATCH] 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 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c index 3298b8a584..89ed898c84 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;