diff options
author | Dan Nicholson <dbn.lists@gmail.com> | 2012-11-29 06:38:24 -0800 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2012-12-03 07:05:43 -0800 |
commit | be455b79fe62e2de976e5aef61c04c73c6857f6a (patch) | |
tree | e5f9c66a9ef489ab9768dc587a28b0c9411acae8 | |
parent | 428362266e77d976e3579d2efaa53ec28bd51d97 (diff) | |
download | pkg-config-be455b79fe62e2de976e5aef61c04c73c6857f6a.tar.gz |
Traverse list backwards instead of copying and reversing
Walking a GSList backwards involved copying and reversing it so that the
the original list could remain undisturbed. This is wasteful with a
GList where we can just start at the end of the list and work backwards.
-rw-r--r-- | pkg.c | 9 |
1 files changed, 2 insertions, 7 deletions
@@ -462,13 +462,10 @@ string_list_strip_duplicates_from_back (GList *list) GHashTable *table; GList *tmp; GList *nodups = NULL; - GList *reversed; table = g_hash_table_new (g_str_hash, g_str_equal); - reversed = g_list_reverse (g_list_copy (list)); - - tmp = reversed; + tmp = g_list_last (list); while (tmp != NULL) { if (g_hash_table_lookup (table, tmp->data) == NULL) @@ -482,10 +479,8 @@ string_list_strip_duplicates_from_back (GList *list) debug_spew (" removing duplicate (from back) \"%s\"\n", tmp->data); } - tmp = g_list_next (tmp); + tmp = g_list_previous (tmp); } - - g_list_free (reversed); g_hash_table_destroy (table); |