[cogl] object: avoid creating a new entry for NULL data



commit ed06d0ca0119f68612628a4871632b3a48a187d6
Author: Robert Bragg <robert linux intel com>
Date:   Sun Feb 19 22:48:51 2012 +0000

    object: avoid creating a new entry for NULL data
    
    If setting NULL user data via cogl_object_set_user_data() and we fail to
    find an entry for the given key then bail out before potentially
    allocating a new entry since setting NULL data is documented to
    effectively delete an entry.
    
    Reviewed-by: Neil Roberts <neil linux intel com>

 cogl/cogl-object.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
---
diff --git a/cogl/cogl-object.c b/cogl/cogl-object.c
index 4e0b4ed..9ae29f7 100644
--- a/cogl/cogl-object.c
+++ b/cogl/cogl-object.c
@@ -190,6 +190,12 @@ _cogl_object_set_user_data (CoglObject *object,
     }
   else
     {
+      /* NB: Setting a value of NULL is documented to delete the
+       * corresponding entry so we can return immediately in this
+       * case. */
+      if (user_data == NULL)
+        return;
+
       if (G_LIKELY (object->n_user_data_entries <
                     COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES))
         entry = &object->user_data_entry[object->n_user_data_entries++];



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