mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-11 20:06:18 +01:00
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
This commit is contained in:
parent
9e81709012
commit
393503ba5b
17
glib/gmain.c
17
glib/gmain.c
@ -2047,9 +2047,8 @@ g_source_unref (GSource *source)
|
|||||||
**/
|
**/
|
||||||
GSource *
|
GSource *
|
||||||
g_main_context_find_source_by_id (GMainContext *context,
|
g_main_context_find_source_by_id (GMainContext *context,
|
||||||
guint source_id)
|
guint source_id)
|
||||||
{
|
{
|
||||||
GSourceIter iter;
|
|
||||||
GSource *source;
|
GSource *source;
|
||||||
|
|
||||||
g_return_val_if_fail (source_id > 0, NULL);
|
g_return_val_if_fail (source_id > 0, NULL);
|
||||||
@ -2058,18 +2057,12 @@ g_main_context_find_source_by_id (GMainContext *context,
|
|||||||
context = g_main_context_default ();
|
context = g_main_context_default ();
|
||||||
|
|
||||||
LOCK_CONTEXT (context);
|
LOCK_CONTEXT (context);
|
||||||
|
source = g_hash_table_lookup (context->sources, GUINT_TO_POINTER (source_id));
|
||||||
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);
|
|
||||||
|
|
||||||
UNLOCK_CONTEXT (context);
|
UNLOCK_CONTEXT (context);
|
||||||
|
|
||||||
|
if (source && SOURCE_DESTROYED (source))
|
||||||
|
source = NULL;
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user