/pidgin/main: 5b4df5b31fb2: Use a box reference count for GntTre...
Ankit Vani
a at nevitus.org
Sat Feb 22 14:54:06 EST 2014
Changeset: 5b4df5b31fb21410b5e200aa0f70ef580d3da08b
Author: Ankit Vani <a at nevitus.org>
Date: 2014-02-23 01:23 +0530
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/5b4df5b31fb2
Description:
Use a box reference count for GntTreeRow's GBoxed copy and free functions
diffstat:
finch/libgnt/gnttree.c | 25 +++++++++++++++++--------
1 files changed, 17 insertions(+), 8 deletions(-)
diffs (53 lines):
diff --git a/finch/libgnt/gnttree.c b/finch/libgnt/gnttree.c
--- a/finch/libgnt/gnttree.c
+++ b/finch/libgnt/gnttree.c
@@ -70,6 +70,8 @@ struct _GntTreePriv
* ... Probably not */
struct _GntTreeRow
{
+ int box_count;
+
void *key;
void *data; /* XXX: unused */
@@ -1959,16 +1961,23 @@ GntTreeRow * gnt_tree_row_get_parent(Gnt
* 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_new;
+ return row;
+}
+
+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 @@ gnt_tree_row_get_type(void)
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;
More information about the Commits
mailing list