summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2012-11-29 05:54:29 -0800
committerDan Nicholson <dbn.lists@gmail.com>2012-11-29 05:54:29 -0800
commit840cf3c97e793877388396a43dd2048f361eac67 (patch)
treedaa0f6e911a309ceeb9e1d6694b7a01cec32ee91
parent160177d8d26c536dc085f938eadc8a43d9f2df29 (diff)
downloadpkg-config-840cf3c97e793877388396a43dd2048f361eac67.tar.gz
Use standard GSList functions to merge package lists
Using the GSList functions instead of manually adjusting the list pointers seems safer and allows an easier path to using another glib list type if necessary.
-rw-r--r--pkg.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/pkg.c b/pkg.c
index a7359ab..2f8bfe6 100644
--- a/pkg.c
+++ b/pkg.c
@@ -655,28 +655,20 @@ merge_flag_lists (GSList *packages, GetListFunc func, GSList **listp)
GSList *last = NULL;
GSList *flags;
+ /* keep track of the last element to avoid traversing the whole list */
for (pkg = packages; pkg != NULL; pkg = pkg->next)
{
- /* manually copy the elements so we can keep track of the end */
for (flags = (*func) (pkg->data); flags != NULL; flags = flags->next)
{
if (last == NULL)
{
- *listp = g_slist_alloc ();
+ *listp = g_slist_prepend (NULL, flags->data);
last = *listp;
}
else
- {
- last->next = g_slist_alloc ();
- last = last->next;
- }
- last->data = flags->data;
+ last = g_slist_next (g_slist_append (last, flags->data));
}
}
-
- /* terminate the last element */
- if (last != NULL)
- last->next = NULL;
}
static void