Sun, 23 Feb 2014 01:23:52 +0530
Use a box reference count for GntTreeRow's GBoxed copy and free functions
| finch/libgnt/gnttree.c | file | annotate | diff | comparison | revisions |
--- a/finch/libgnt/gnttree.c Fri Feb 21 02:49:57 2014 +0530 +++ b/finch/libgnt/gnttree.c Sun Feb 23 01:23:52 2014 +0530 @@ -70,6 +70,8 @@ * ... Probably not */ struct _GntTreeRow { + int box_count; + void *key; void *data; /* XXX: unused */ @@ -1959,16 +1961,23 @@ * GntTreeRow GBoxed API **************************************************************************/ static GntTreeRow * -copy_tree_row(GntTreeRow *row) +gnt_tree_row_ref(GntTreeRow *row) { - GntTreeRow *row_new; - g_return_val_if_fail(row != NULL, NULL); - row_new = g_new(GntTreeRow, 1); - *row_new = *row; + row->box_count++; + + return row; +} - return row_new; +static void +gnt_tree_row_unref(GntTreeRow *row) +{ + g_return_if_fail(row != NULL); + g_return_if_fail(row->box_count >= 0); + + if (!row->box_count--) + free_tree_row(row); } GType @@ -1978,8 +1987,8 @@ if (type == 0) { type = g_boxed_type_register_static("GntTreeRow", - (GBoxedCopyFunc)copy_tree_row, - (GBoxedFreeFunc)free_tree_row); + (GBoxedCopyFunc)gnt_tree_row_ref, + (GBoxedFreeFunc)gnt_tree_row_unref); } return type;