objects: use GPtrArray instead of GArray
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 17 Mar 2015 20:36:55 +0000 (16:36 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 19 Mar 2015 18:07:10 +0000 (14:07 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
lib/objects.c

index 7fb348416520bb3dd0cdc87af866b86144b6aceb..5ac72c55d21675dcf66133b38a99500fabef77fa 100644 (file)
@@ -76,7 +76,7 @@ struct bt_object_string {
 
 struct bt_object_array {
        struct bt_object base;
-       GArray *garray;
+       GPtrArray *garray;
 };
 
 struct bt_object_map {
@@ -95,18 +95,11 @@ void bt_object_string_destroy(struct bt_object *object)
 static
 void bt_object_array_destroy(struct bt_object *object)
 {
-       int x;
-       struct bt_object_array *array_obj = BT_OBJECT_TO_ARRAY(object);
-
-       for (x = 0; x < array_obj->garray->len; ++x) {
-               struct bt_object *el_obj;
-
-               el_obj = g_array_index(array_obj->garray,
-                       struct bt_object *, x);
-               bt_object_put(el_obj);
-       }
-
-       g_array_free(array_obj->garray, TRUE);
+       /*
+        * Pointer array's registered value destructor will take care
+        * of putting each contained object.
+        */
+       g_ptr_array_free(BT_OBJECT_TO_ARRAY(object)->garray, TRUE);
 }
 
 static
@@ -564,8 +557,8 @@ struct bt_object *bt_object_array_create(void)
        }
 
        array_obj->base = bt_object_create_base(BT_OBJECT_TYPE_ARRAY);
-       array_obj->garray = g_array_new(FALSE, FALSE,
-               sizeof(struct bt_object *));
+       array_obj->garray = g_ptr_array_new_full(0,
+               (GDestroyNotify) bt_object_put);
 
        if (!array_obj->garray) {
                g_free(array_obj);
@@ -770,8 +763,7 @@ struct bt_object *bt_object_array_get(const struct bt_object *array_obj,
                goto end;
        }
 
-       ret = g_array_index(typed_array_obj->garray,
-               struct bt_object *, index);
+       ret = g_ptr_array_index(typed_array_obj->garray, index);
        bt_object_get(ret);
 
 end:
@@ -790,7 +782,7 @@ int bt_object_array_append(struct bt_object *array_obj,
                goto end;
        }
 
-       g_array_append_val(typed_array_obj->garray, element_obj);
+       g_ptr_array_add(typed_array_obj->garray, element_obj);
        bt_object_get(element_obj);
 
 end:
This page took 0.029829 seconds and 4 git commands to generate.