[Telepathy-commits] [telepathy-gabble/master] simplify gabble_private_tubes_factory_caps_diff as we did in Salut
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Tue Jan 27 04:45:17 PST 2009
---
src/private-tubes-factory.c | 97 ++++++++++++++++++-------------------------
1 files changed, 41 insertions(+), 56 deletions(-)
diff --git a/src/private-tubes-factory.c b/src/private-tubes-factory.c
index b7f82da..ba0c655 100644
--- a/src/private-tubes-factory.c
+++ b/src/private-tubes-factory.c
@@ -665,6 +665,24 @@ gabble_private_tubes_factory_update_caps (
}
static gboolean
+hash_table_is_subset (GHashTable *superset,
+ GHashTable *subset)
+{
+ GHashTableIter iter;
+ gpointer look_for;
+
+ g_hash_table_iter_init (&iter, subset);
+ while (g_hash_table_iter_next (&iter, &look_for, NULL))
+ {
+ if (!g_hash_table_lookup_extended (superset, look_for, NULL, NULL))
+ /* One of subset's key is not in superset */
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
gabble_private_tubes_factory_caps_diff (
GabbleCapsChannelManager *manager,
TpHandle handle,
@@ -673,64 +691,31 @@ gabble_private_tubes_factory_caps_diff (
{
TubesCapabilities *old_caps = specific_old_caps;
TubesCapabilities *new_caps = specific_new_caps;
- GHashTableIter tube_caps_iter;
- gpointer service;
- if (old_caps != NULL)
- {
- g_hash_table_iter_init (&tube_caps_iter, old_caps->stream_tube_caps);
- while (g_hash_table_iter_next (&tube_caps_iter, &service,
- NULL))
- {
- gpointer key, value;
- if (new_caps == NULL ||
- !g_hash_table_lookup_extended (new_caps->stream_tube_caps,
- service, &key, &value))
- {
- return TRUE;
- }
- }
- g_hash_table_iter_init (&tube_caps_iter, old_caps->dbus_tube_caps);
- while (g_hash_table_iter_next (&tube_caps_iter, &service,
- NULL))
- {
- gpointer key, value;
- if (new_caps == NULL ||
- !g_hash_table_lookup_extended (new_caps->dbus_tube_caps,
- service, &key, &value))
- {
- return TRUE;
- }
- }
- }
+ if (old_caps == NULL && new_caps == NULL)
+ return FALSE;
+
+ /* At most one of the caps is NULL at this point */
+ if (old_caps == new_caps || old_caps == NULL || new_caps == NULL)
+ return TRUE;
+
+ if (g_hash_table_size (old_caps->stream_tube_caps) !=
+ g_hash_table_size (new_caps->stream_tube_caps))
+ return TRUE;
+
+ if (g_hash_table_size (old_caps->dbus_tube_caps) !=
+ g_hash_table_size (new_caps->dbus_tube_caps))
+ return TRUE;
+
+ /* Hash tables have the same size */
+ if (!hash_table_is_subset (new_caps->stream_tube_caps,
+ old_caps->stream_tube_caps))
+ return TRUE;
+
+ if (!hash_table_is_subset (new_caps->dbus_tube_caps,
+ old_caps->dbus_tube_caps))
+ return TRUE;
- if (new_caps != NULL)
- {
- g_hash_table_iter_init (&tube_caps_iter, new_caps->stream_tube_caps);
- while (g_hash_table_iter_next (&tube_caps_iter, &service,
- NULL))
- {
- gpointer key, value;
- if (old_caps == NULL ||
- !g_hash_table_lookup_extended (old_caps->stream_tube_caps,
- service, &key, &value))
- {
- return TRUE;
- }
- }
- g_hash_table_iter_init (&tube_caps_iter, new_caps->dbus_tube_caps);
- while (g_hash_table_iter_next (&tube_caps_iter, &service,
- NULL))
- {
- gpointer key, value;
- if (old_caps == NULL ||
- !g_hash_table_lookup_extended (old_caps->dbus_tube_caps,
- service, &key, &value))
- {
- return TRUE;
- }
- }
- }
return FALSE;
}
--
1.5.6.5
More information about the Telepathy-commits
mailing list