summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2012-12-03 08:25:40 -0800
committerDan Nicholson <dbn.lists@gmail.com>2012-12-03 08:25:40 -0800
commit428335e2b55c368955269e97370e2185c08a47db (patch)
tree579de1405717e4a92cd7721c141f363c55977397
parenta7b465806f4111355d450349fb6ef78175fc91be (diff)
downloadpkg-config-428335e2b55c368955269e97370e2185c08a47db.tar.gz
Optimize hash table when usage is only as a set
When searching for duplicate strings in the output list, a hash table is used to keep track of which strings have been seen. This usage as a set can be optimized as described in the documentation to not allocate or free the hash table values: http://developer.gnome.org/glib/stable/glib-Hash-Tables.html#glib-Hash-Tables.description
-rw-r--r--pkg.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/pkg.c b/pkg.c
index 82c967d..c2f9825 100644
--- a/pkg.c
+++ b/pkg.c
@@ -433,10 +433,10 @@ string_list_strip_duplicates (GList *list)
table = g_hash_table_new (g_str_hash, g_str_equal);
for (tmp = list; tmp != NULL; tmp = g_list_next (tmp))
{
- if (g_hash_table_lookup (table, tmp->data) == NULL)
+ if (!g_hash_table_lookup_extended (table, tmp->data, NULL, NULL))
{
/* Unique string. Track it and and move to the next. */
- g_hash_table_insert (table, tmp->data, tmp->data);
+ g_hash_table_replace (table, tmp->data, tmp->data);
}
else
{
@@ -462,10 +462,10 @@ string_list_strip_duplicates_from_back (GList *list)
table = g_hash_table_new (g_str_hash, g_str_equal);
for (tmp = g_list_last (list); tmp != NULL; tmp = g_list_previous (tmp))
{
- if (g_hash_table_lookup (table, tmp->data) == NULL)
+ if (!g_hash_table_lookup_extended (table, tmp->data, NULL, NULL))
{
/* Unique string. Track it and and move to the next. */
- g_hash_table_insert (table, tmp->data, tmp->data);
+ g_hash_table_replace (table, tmp->data, tmp->data);
}
else
{
@@ -681,7 +681,7 @@ package_list_strip_duplicates (GList *packages)
{
Package *pkg = cur->data;
- if (g_hash_table_lookup (requires, pkg->key) != NULL)
+ if (g_hash_table_lookup_extended (requires, pkg->key, NULL, NULL))
{
GList *dup = cur;
@@ -693,7 +693,7 @@ package_list_strip_duplicates (GList *packages)
else
{
/* Unique package. Track it and move to the next. */
- g_hash_table_insert (requires, pkg->key, pkg);
+ g_hash_table_replace (requires, pkg->key, pkg);
}
}
g_hash_table_destroy (requires);