summaryrefslogtreecommitdiff
path: root/glib
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2014-02-08 12:23:46 +0000
committerRyan Lortie <desrt@desrt.ca>2014-02-24 09:28:43 -0500
commit393503ba5bdc7c09cd46b716aaf3d2c63a6c7f9c (patch)
tree4afc71f17763efcf4f06b5427dd202d8702cd0e0 /glib
parent9e81709012f27eebe336f40f948e9493c87fc75b (diff)
gmain: simplify g_main_context_find_source_by_id()
Since we now keep a hashtable of sources, we can implement this function without iteration. https://bugzilla.gnome.org/show_bug.cgi?id=724839
Diffstat (limited to 'glib')
-rw-r--r--glib/gmain.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/glib/gmain.c b/glib/gmain.c
index 404833d94..45ed40250 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -2039,37 +2039,30 @@ g_source_unref (GSource *source)
/**
* g_main_context_find_source_by_id:
* @context: (allow-none): a #GMainContext (if %NULL, the default context will be used)
- * @source_id: the source ID, as returned by g_source_get_id().
- *
+ * @source_id: the source ID, as returned by g_source_get_id().
+ *
* Finds a #GSource given a pair of context and ID.
- *
+ *
* Returns: (transfer none): the #GSource if found, otherwise, %NULL
**/
GSource *
g_main_context_find_source_by_id (GMainContext *context,
- guint source_id)
+ guint source_id)
{
- GSourceIter iter;
GSource *source;
-
+
g_return_val_if_fail (source_id > 0, NULL);
if (context == NULL)
context = g_main_context_default ();
-
- LOCK_CONTEXT (context);
-
- g_source_iter_init (&iter, context, FALSE);
- while (g_source_iter_next (&iter, &source))
- {
- if (!SOURCE_DESTROYED (source) &&
- source->source_id == source_id)
- break;
- }
- g_source_iter_clear (&iter);
+ LOCK_CONTEXT (context);
+ source = g_hash_table_lookup (context->sources, GUINT_TO_POINTER (source_id));
UNLOCK_CONTEXT (context);
+ if (source && SOURCE_DESTROYED (source))
+ source = NULL;
+
return source;
}