Author: Phillip Susi <psusi@ubuntu.com>
Description: The dispatch path was using a linked list to maintain
 a stack of the current source being dispatched.  The purpose of
 this was to be able to report the current source, which only
 cares about the top of the stack.  Therefore, there is no point
 to keeping the full stack in a linked list when only the current
 head is needed, so do away with the list and simply stuff the
 previous source in a local on the stack, to be restored post
 dispatch.  This saves some needless pointer manipulation.

--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -217,7 +217,7 @@
 struct _GMainDispatch
 {
   gint depth;
-  GSList *dispatching_sources; /* stack of current sources */
+  GSource *current_source;
 };
 
 #ifdef G_MAIN_POLL_DEBUG
@@ -2853,7 +2853,7 @@
 g_main_current_source (void)
 {
   GMainDispatch *dispatch = get_dispatch ();
-  return dispatch->dispatching_sources ? dispatch->dispatching_sources->data : NULL;
+  return dispatch->current_source ? dispatch->current_source : NULL;
 }
 
 /**
@@ -3025,11 +3025,11 @@
 	  GSourceCallbackFuncs *cb_funcs;
 	  gpointer cb_data;
 	  gboolean need_destroy;
+	  GSource *old_source;
 
 	  gboolean (*dispatch) (GSource *,
 				GSourceFunc,
 				gpointer);
-	  GSList current_source_link;
 
 	  dispatch = source->source_funcs->dispatch;
 	  cb_funcs = source->callback_funcs;
@@ -3050,23 +3050,12 @@
 	  UNLOCK_CONTEXT (context);
 
 	  current->depth++;
-	  /* The on-stack allocation of the GSList is unconventional, but
-	   * we know that the lifetime of the link is bounded to this
-	   * function as the link is kept in a thread specific list and
-	   * not manipulated outside of this function and its descendants.
-	   * Avoiding the overhead of a g_slist_alloc() is useful as many
-	   * applications do little more than dispatch events.
-	   *
-	   * This is a performance hack - do not revert to g_slist_prepend()!
-	   */
-	  current_source_link.data = source;
-	  current_source_link.next = current->dispatching_sources;
-	  current->dispatching_sources = &current_source_link;
+	  old_source = current->current_source;
+	  current->current_source = source;
 	  need_destroy = ! dispatch (source,
 				     callback,
 				     user_data);
-	  g_assert (current->dispatching_sources == &current_source_link);
-	  current->dispatching_sources = current_source_link.next;
+	  current->current_source = old_source;
 	  current->depth--;
 	  
 	  if (cb_funcs)
