[gnome-software/wip/hughsie/unique-id-hash: 5/5] Use the new unique_id hash functions



commit bfe02389102089e93ebfa6e30d3136a32ae0c3f4
Author: Richard Hughes <richard hughsie com>
Date:   Thu Aug 25 12:45:05 2016 +0100

    Use the new unique_id hash functions
    
    These functions respect the globbing rules unlike g_str_hash() and g_str_equal().

 src/gs-app-list.c |    7 +++++++
 src/gs-plugin.c   |    7 +++++++
 2 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app-list.c b/src/gs-app-list.c
index c9618e4..0758e1f 100644
--- a/src/gs-app-list.c
+++ b/src/gs-app-list.c
@@ -82,6 +82,7 @@ gs_app_list_add (GsAppList *list, GsApp *app)
                return;
        }
 
+#if !AS_CHECK_VERSION(0,6,2)
        /* check for duplicate using globs (slower) */
        for (i = 0; i < list->array->len; i++) {
                GsApp *app_tmp = g_ptr_array_index (list->array, i);
@@ -93,6 +94,7 @@ gs_app_list_add (GsAppList *list, GsApp *app)
                        return;
                }
        }
+#endif
 
        /* just use the ref */
        g_ptr_array_add (list->array, g_object_ref (app));
@@ -390,7 +392,12 @@ static void
 gs_app_list_init (GsAppList *list)
 {
        list->array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+#if AS_CHECK_VERSION(0,6,2)
+       list->hash_by_id = g_hash_table_new (as_utils_unique_id_hash_safe,
+                                            as_utils_unique_id_equal_safe);
+#else
        list->hash_by_id = g_hash_table_new (g_str_hash, g_str_equal);
+#endif
 }
 
 /**
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 76ad484..16d08e7 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -1274,10 +1274,17 @@ gs_plugin_init (GsPlugin *plugin)
        priv->enabled = TRUE;
        priv->scale = 1;
        priv->profile = as_profile_new ();
+#if AS_CHECK_VERSION(0,6,2)
+       priv->cache = g_hash_table_new_full (as_utils_unique_id_hash_safe,
+                                            as_utils_unique_id_equal_safe,
+                                            g_free,
+                                            (GDestroyNotify) g_object_unref);
+#else
        priv->cache = g_hash_table_new_full (g_str_hash,
                                             g_str_equal,
                                             g_free,
                                             (GDestroyNotify) g_object_unref);
+#endif
        g_mutex_init (&priv->cache_mutex);
        g_mutex_init (&priv->timer_mutex);
        g_rw_lock_init (&priv->rwlock);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]