diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2011-10-03 12:57:41 +0100 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2011-10-03 12:57:41 +0100 |
commit | c3f9dd779c1d780eab6d0de8be510c2ea45fc796 (patch) | |
tree | 1b668921a16bdf5b28eff848c6460809c0fece25 | |
parent | a899ab819ccb3f60b083822eedb0f7989bee3707 (diff) |
MessageMixin: track messages to be acked in a GPtrArray
Since 'ids' may contain duplicates (which a future patch will filter
out), using an array of GList *s is a bit cumbersome: we'd have to be
sure not to index elements of it which haven't been initialized. Using a
GPtrArray is clearer.
-rw-r--r-- | telepathy-glib/message-mixin.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/telepathy-glib/message-mixin.c b/telepathy-glib/message-mixin.c index 8bfc6dc05..02adc8059 100644 --- a/telepathy-glib/message-mixin.c +++ b/telepathy-glib/message-mixin.c @@ -389,19 +389,18 @@ tp_message_mixin_acknowledge_pending_messages_async ( DBusGMethodInvocation *context) { TpMessageMixin *mixin = TP_MESSAGE_MIXIN (iface); - GList **nodes; + GPtrArray *links = g_ptr_array_sized_new (ids->len); guint i; - nodes = g_new (GList *, ids->len); - for (i = 0; i < ids->len; i++) { guint id = g_array_index (ids, guint, i); + GList *link_; - nodes[i] = g_queue_find_custom (mixin->priv->pending, + link_ = g_queue_find_custom (mixin->priv->pending, GUINT_TO_POINTER (id), pending_item_id_equals_data); - if (nodes[i] == NULL) + if (link_ == NULL) { GError *error = g_error_new (TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, "invalid message id %u", id); @@ -410,19 +409,22 @@ tp_message_mixin_acknowledge_pending_messages_async ( dbus_g_method_return_error (context, error); g_error_free (error); - g_free (nodes); + g_ptr_array_unref (links); return; } + + g_ptr_array_add (links, link_); } tp_svc_channel_interface_messages_emit_pending_messages_removed (iface, ids); - for (i = 0; i < ids->len; i++) + for (i = 0; i < links->len; i++) { - TpMessage *item = nodes[i]->data; + GList *link_ = g_ptr_array_index (links, i); + TpMessage *item = link_->data; #ifdef ENABLE_DEBUG - TpCMMessage *cm_msg = nodes[i]->data; + TpCMMessage *cm_msg = link_->data; #endif DEBUG ("acknowledging message id %u", cm_msg->incoming_id); @@ -431,7 +433,7 @@ tp_message_mixin_acknowledge_pending_messages_async ( tp_message_destroy (item); } - g_free (nodes); + g_ptr_array_unref (links); tp_svc_channel_type_text_return_from_acknowledge_pending_messages (context); } |