[glib/wip/source-api: 1/5] GSource: initialise ->priv on construct
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/source-api: 1/5] GSource: initialise ->priv on construct
- Date: Tue, 30 Aug 2011 23:15:38 +0000 (UTC)
commit 24a188622ab4cc57d2d08a9fee420a024b8b74c9
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 75c2c0e..9f57af8 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -828,7 +828,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;
@@ -849,7 +849,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;
@@ -915,14 +915,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;
@@ -1004,7 +1001,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
@@ -1200,18 +1197,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;
@@ -1242,7 +1234,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));
@@ -1434,7 +1426,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)
@@ -1693,11 +1685,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);
}
@@ -2772,7 +2761,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;
}
}
}
@@ -2968,7 +2957,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]