From a22a5f1b0b312d5424f5f1105cdedbee9f8d7c18 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 17 Mar 2015 16:36:55 -0400 Subject: [PATCH] objects: use GPtrArray instead of GArray MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- lib/objects.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/lib/objects.c b/lib/objects.c index 7fb34841..5ac72c55 100644 --- a/lib/objects.c +++ b/lib/objects.c @@ -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: -- 2.34.1