[gnome-builder] egg-task-cache: Allow NULL as key_copy_func and key_destroy_func



commit 50c07336cd8f33a84dbf423dd3293772b30d5cbb
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Feb 28 10:50:21 2017 +0100

    egg-task-cache: Allow NULL as key_copy_func and key_destroy_func
    
    This makes it convenient to use raw gpointers as keys. Dummy copy and
    destroy functions were added to avoid branching everywhere.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779363

 contrib/egg/egg-task-cache.c |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/contrib/egg/egg-task-cache.c b/contrib/egg/egg-task-cache.c
index 3d466eb..0bc4598 100644
--- a/contrib/egg/egg-task-cache.c
+++ b/contrib/egg/egg-task-cache.c
@@ -220,6 +220,17 @@ cache_item_new (EggTaskCache  *self,
   return ret;
 }
 
+static gpointer
+egg_task_cache_dummy_copy_func (gpointer boxed)
+{
+  return boxed;
+}
+
+static void
+egg_task_cache_dummy_destroy_func (gpointer boxed)
+{
+}
+
 static gboolean
 egg_task_cache_evict_full (EggTaskCache  *self,
                            gconstpointer  key,
@@ -592,9 +603,7 @@ egg_task_cache_constructed (GObject *object)
 
   G_OBJECT_CLASS (egg_task_cache_parent_class)->constructed (object);
 
-  if ((self->key_copy_func == NULL) ||
-      (self->key_destroy_func == NULL) ||
-      (self->key_equal_func == NULL) ||
+  if ((self->key_equal_func == NULL) ||
       (self->key_hash_func == NULL) ||
       (self->value_copy_func == NULL) ||
       (self->value_destroy_func == NULL) ||
@@ -604,6 +613,12 @@ egg_task_cache_constructed (GObject *object)
       return;
     }
 
+  if (self->key_copy_func == NULL)
+    self->key_copy_func = egg_task_cache_dummy_copy_func;
+
+  if (self->key_destroy_func == NULL)
+    self->key_destroy_func = egg_task_cache_dummy_destroy_func;
+
   /*
    * This is where the cached result objects live.
    */
@@ -880,8 +895,6 @@ egg_task_cache_new (GHashFunc            key_hash_func,
 {
   g_return_val_if_fail (key_hash_func, NULL);
   g_return_val_if_fail (key_equal_func, NULL);
-  g_return_val_if_fail (key_copy_func, NULL);
-  g_return_val_if_fail (key_destroy_func, NULL);
   g_return_val_if_fail (populate_callback, NULL);
 
   return g_object_new (EGG_TYPE_TASK_CACHE,


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