[glib/wip/glib-next: 23/27] GSource: initialise ->priv on construct



commit e7c0f1b52f31a932184cccd857c56ab86c2f1dfe
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue Aug 30 12:15:04 2011 -0400

    GSource: initialise ->priv on construct
    
    For efficiency, we waited until setting up child sources to allocate
    ->priv.  Simplify things a bit by allocating it from the start.

 glib/gmain.c |   39 ++++++++++++++-------------------------
 1 files changed, 14 insertions(+), 25 deletions(-)
---
diff --git a/glib/gmain.c b/glib/gmain.c
index f01bc46..324f751 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -769,7 +769,7 @@ g_source_new (GSourceFuncs *source_funcs,
   g_return_val_if_fail (struct_size >= sizeof (GSource), NULL);
   
   source = (GSource*) g_malloc0 (struct_size);
-
+  source->priv = g_slice_new0 (GSourcePrivate);
   source->source_funcs = source_funcs;
   source->ref_count = 1;
   
@@ -790,7 +790,7 @@ g_source_list_add (GSource      *source,
 {
   GSource *tmp_source, *last_source;
   
-  if (source->priv && source->priv->parent_source)
+  if (source->priv->parent_source)
     {
       /* Put the source immediately before its parent */
       tmp_source = source->priv->parent_source;
@@ -856,14 +856,11 @@ g_source_attach_unlocked (GSource      *source,
       tmp_list = tmp_list->next;
     }
 
-  if (source->priv)
+  tmp_list = source->priv->child_sources;
+  while (tmp_list)
     {
-      tmp_list = source->priv->child_sources;
-      while (tmp_list)
-	{
-	  g_source_attach_unlocked (tmp_list->data, context);
-	  tmp_list = tmp_list->next;
-	}
+      g_source_attach_unlocked (tmp_list->data, context);
+      tmp_list = tmp_list->next;
     }
 
   return result;
@@ -943,7 +940,7 @@ g_source_destroy_internal (GSource      *source,
 	    }
 	}
 
-      if (source->priv && source->priv->child_sources)
+      if (source->priv->child_sources)
 	{
 	  /* This is safe because even if a child_source finalizer or
 	   * closure notify tried to modify source->priv->child_sources
@@ -1139,18 +1136,13 @@ g_source_add_child_source (GSource *source,
   g_return_if_fail (!SOURCE_DESTROYED (source));
   g_return_if_fail (!SOURCE_DESTROYED (child_source));
   g_return_if_fail (child_source->context == NULL);
-  g_return_if_fail (child_source->priv == NULL || child_source->priv->parent_source == NULL);
+  g_return_if_fail (child_source->priv->parent_source == NULL);
 
   context = source->context;
 
   if (context)
     LOCK_CONTEXT (context);
 
-  if (!source->priv)
-    source->priv = g_slice_new0 (GSourcePrivate);
-  if (!child_source->priv)
-    child_source->priv = g_slice_new0 (GSourcePrivate);
-
   source->priv->child_sources = g_slist_prepend (source->priv->child_sources,
 						 g_source_ref (child_source));
   child_source->priv->parent_source = source;
@@ -1181,7 +1173,7 @@ g_source_remove_child_source (GSource *source,
 
   g_return_if_fail (source != NULL);
   g_return_if_fail (child_source != NULL);
-  g_return_if_fail (child_source->priv != NULL && child_source->priv->parent_source == source);
+  g_return_if_fail (child_source->priv->parent_source == source);
   g_return_if_fail (!SOURCE_DESTROYED (source));
   g_return_if_fail (!SOURCE_DESTROYED (child_source));
 
@@ -1373,7 +1365,7 @@ g_source_set_priority_unlocked (GSource      *source,
 	}
     }
 
-  if (source->priv && source->priv->child_sources)
+  if (source->priv->child_sources)
     {
       tmp_list = source->priv->child_sources;
       while (tmp_list)
@@ -1632,11 +1624,8 @@ g_source_unref_internal (GSource      *source,
       g_slist_free (source->poll_fds);
       source->poll_fds = NULL;
 
-      if (source->priv)
-	{
-	  g_slice_free (GSourcePrivate, source->priv);
-	  source->priv = NULL;
-	}
+      g_slice_free (GSourcePrivate, source->priv);
+      source->priv = NULL;
 
       g_free (source);
     }
@@ -2698,7 +2687,7 @@ g_main_context_prepare (GMainContext *context,
 	      while (ready_source)
 		{
 		  ready_source->flags |= G_SOURCE_READY;
-		  ready_source = ready_source->priv ? ready_source->priv->parent_source : NULL;
+		  ready_source = ready_source->priv->parent_source;
 		}
 	    }
 	}
@@ -2890,7 +2879,7 @@ g_main_context_check (GMainContext *context,
 	      while (ready_source)
 		{
 		  ready_source->flags |= G_SOURCE_READY;
-		  ready_source = ready_source->priv ? ready_source->priv->parent_source : NULL;
+		  ready_source = ready_source->priv->parent_source;
 		}
 	    }
 	}



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