diff options
author | Dan Williams <dcbw@redhat.com> | 2010-03-24 14:40:09 -0700 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2010-03-24 20:13:49 -0400 |
commit | 551d86f7fe0e7f2304f57baa7a406c935182b06a (patch) | |
tree | 2b099351221ee5dd72bbca76ce78e714e8d0496b | |
parent | ed73cb2f32c411a3306c6dfe2ae541aea249f200 (diff) |
core: performance optimization for object info lookup
-rw-r--r-- | dbus/dbus-gobject.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/dbus/dbus-gobject.c b/dbus/dbus-gobject.c index b67df10..3e7914d 100644 --- a/dbus/dbus-gobject.c +++ b/dbus/dbus-gobject.c @@ -301,9 +301,10 @@ dbus_g_object_type_dbus_metadata_quark (void) return quark; } -typedef void (*ForeachObjectInfoFn) (const DBusGObjectInfo *info, - GType gtype, - gpointer user_data); +/* Iterator function should return FALSE to stop iteration, TRUE to continue */ +typedef gboolean (*ForeachObjectInfoFn) (const DBusGObjectInfo *info, + GType gtype, + gpointer user_data); static void foreach_object_info (GObject *object, @@ -320,7 +321,10 @@ foreach_object_info (GObject *object, { info = g_type_get_qdata (*p, dbus_g_object_type_dbus_metadata_quark ()); if (info != NULL && info->format_version >= 0) - callback (info, *p, user_data); + { + if (!callback (info, *p, user_data)) + break; + } } g_free (interfaces); @@ -329,12 +333,15 @@ foreach_object_info (GObject *object, { info = g_type_get_qdata (classtype, dbus_g_object_type_dbus_metadata_quark ()); if (info != NULL && info->format_version >= 0) - callback (info, classtype, user_data); + { + if (!callback (info, classtype, user_data)) + break; + } } } -static void +static gboolean lookup_object_info_cb (const DBusGObjectInfo *info, GType gtype, gpointer user_data) @@ -342,6 +349,7 @@ lookup_object_info_cb (const DBusGObjectInfo *info, GList **list = (GList **) user_data; *list = g_list_prepend (*list, (gpointer) info); + return TRUE; } static GList * @@ -361,29 +369,26 @@ typedef struct { GType iface_type; } LookupObjectInfoByIfaceData; -static void +static gboolean lookup_object_info_by_iface_cb (const DBusGObjectInfo *info, GType gtype, gpointer user_data) { LookupObjectInfoByIfaceData *lookup_data = (LookupObjectInfoByIfaceData *) user_data; - if (lookup_data->info) - return; - /* If interface is not specified, choose the first info */ if (lookup_data->fallback && (!lookup_data->iface || strlen (lookup_data->iface) == 0)) { lookup_data->info = info; lookup_data->iface_type = gtype; - return; } - - if (info->exported_properties && !strcmp (info->exported_properties, lookup_data->iface)) + else if (info->exported_properties && !strcmp (info->exported_properties, lookup_data->iface)) { lookup_data->info = info; lookup_data->iface_type = gtype; } + + return !lookup_data->info; } static const DBusGObjectInfo * |