[glib/wip/gmaincontext: 2/12] gmain: simplify g_main_context_find_source_by_id()
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/gmaincontext: 2/12] gmain: simplify g_main_context_find_source_by_id()
- Date: Sun, 16 Feb 2014 15:16:12 +0000 (UTC)
commit 7836fce0cdb476432dff86c4f18dc59109dc2ef5
Author: Ryan Lortie <desrt desrt ca>
Date: Sat Feb 8 12:23:46 2014 +0000
gmain: simplify g_main_context_find_source_by_id()
Since we now keep a hashtable of sources, we can implement this function
without iteration.
glib/gmain.c | 27 ++++++++++-----------------
1 files changed, 10 insertions(+), 17 deletions(-)
---
diff --git a/glib/gmain.c b/glib/gmain.c
index 2f166fb..4e72c1e 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -2015,37 +2015,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.
- *
+ *
* Return value: (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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]