[next] telepathy-glib: Modernise GList usage
Xavier Claessens
xclaesse at kemper.freedesktop.org
Fri Sep 7 12:08:56 PDT 2012
Module: telepathy-glib
Branch: next
Commit: 625f553077d234316b81ae81f399c99917217ae7
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=625f553077d234316b81ae81f399c99917217ae7
Author: Xavier Claessens <xavier.claessens at collabora.co.uk>
Date: Wed Sep 5 11:11:41 2012 +0200
Modernise GList usage
We can use g_list_free_full and (_tp_)g_list_copy_deep in more places
---
telepathy-glib/base-client.c | 3 +--
telepathy-glib/connection-contact-info.c | 28 ++++++----------------------
telepathy-glib/contact-search-result.c | 3 +--
telepathy-glib/contact-search.c | 3 +--
telepathy-glib/util.c | 6 +-----
5 files changed, 10 insertions(+), 33 deletions(-)
diff --git a/telepathy-glib/base-client.c b/telepathy-glib/base-client.c
index 32c17e8..f25c2c9 100644
--- a/telepathy-glib/base-client.c
+++ b/telepathy-glib/base-client.c
@@ -999,8 +999,7 @@ tp_base_client_dispose (GObject *object)
tp_clear_object (&self->priv->only_for_account);
tp_clear_object (&self->priv->channel_factory);
- g_list_foreach (self->priv->pending_requests, (GFunc) g_object_unref, NULL);
- g_list_free (self->priv->pending_requests);
+ g_list_free_full (self->priv->pending_requests, g_object_unref);
self->priv->pending_requests = NULL;
if (self->priv->my_chans != NULL &&
diff --git a/telepathy-glib/connection-contact-info.c b/telepathy-glib/connection-contact-info.c
index 52179e3..7879b2e 100644
--- a/telepathy-glib/connection-contact-info.c
+++ b/telepathy-glib/connection-contact-info.c
@@ -158,15 +158,8 @@ G_DEFINE_BOXED_TYPE (TpContactInfoFieldSpec, tp_contact_info_field_spec,
GList *
tp_contact_info_spec_list_copy (GList *list)
{
- GList *copy = NULL;
-
- while (list != NULL)
- {
- copy = g_list_prepend (copy, tp_contact_info_field_spec_copy (list->data));
- list = list->next;
- }
-
- return g_list_reverse (copy);
+ return _tp_g_list_copy_deep (list,
+ (GCopyFunc) tp_contact_info_field_spec_copy, NULL);
}
/**
@@ -180,8 +173,7 @@ tp_contact_info_spec_list_copy (GList *list)
void
tp_contact_info_spec_list_free (GList *list)
{
- g_list_foreach (list, (GFunc) tp_contact_info_field_spec_free, NULL);
- g_list_free (list);
+ g_list_free_full (list, (GDestroyNotify) tp_contact_info_field_spec_free);
}
/**
@@ -316,15 +308,8 @@ G_DEFINE_BOXED_TYPE (TpContactInfoField, tp_contact_info_field,
GList *
tp_contact_info_list_copy (GList *list)
{
- GList *copy = NULL;
-
- while (list != NULL)
- {
- copy = g_list_prepend (copy, tp_contact_info_field_copy (list->data));
- list = list->next;
- }
-
- return g_list_reverse (copy);
+ return _tp_g_list_copy_deep (list,
+ (GCopyFunc) tp_contact_info_field_copy, NULL);
}
/**
@@ -338,8 +323,7 @@ tp_contact_info_list_copy (GList *list)
void
tp_contact_info_list_free (GList *list)
{
- g_list_foreach (list, (GFunc) tp_contact_info_field_free, NULL);
- g_list_free (list);
+ g_list_free_full (list, (GDestroyNotify) tp_contact_info_field_free);
}
/**
diff --git a/telepathy-glib/contact-search-result.c b/telepathy-glib/contact-search-result.c
index bd77719..c3e7ac3 100644
--- a/telepathy-glib/contact-search-result.c
+++ b/telepathy-glib/contact-search-result.c
@@ -136,8 +136,7 @@ tp_contact_search_result_dispose (GObject *object)
tp_clear_pointer (&self->priv->identifier, g_free);
- g_list_foreach (self->priv->fields, (GFunc) tp_contact_info_field_free, NULL);
- tp_clear_pointer (&self->priv->fields, g_list_free);
+ tp_clear_pointer (&self->priv->fields, tp_contact_info_list_free);
G_OBJECT_CLASS (tp_contact_search_result_parent_class)->dispose (object);
}
diff --git a/telepathy-glib/contact-search.c b/telepathy-glib/contact-search.c
index dacea81..3c87f23 100644
--- a/telepathy-glib/contact-search.c
+++ b/telepathy-glib/contact-search.c
@@ -183,8 +183,7 @@ _search_results_received (TpChannel *channel,
DEBUG ("SearchResultsReceived (%i results)", g_hash_table_size (result));
g_signal_emit (object, _signals[SEARCH_RESULTS_RECEIVED], 0, results);
- g_list_foreach (results, (GFunc) g_object_unref, NULL);
- g_list_free (results);
+ g_list_free_full (results, g_object_unref);
}
static void
diff --git a/telepathy-glib/util.c b/telepathy-glib/util.c
index 250a890..217cf5f 100644
--- a/telepathy-glib/util.c
+++ b/telepathy-glib/util.c
@@ -2037,11 +2037,7 @@ _tp_contacts_from_values (GHashTable *table)
GList *
_tp_object_list_copy (GList *l)
{
- GList *new_l;
-
- new_l = g_list_copy (l);
- g_list_foreach (new_l, (GFunc) g_object_ref, NULL);
- return new_l;
+ return _tp_g_list_copy_deep (l, (GCopyFunc) g_object_ref, NULL);
}
/*
More information about the telepathy-commits
mailing list