[libdazzle] tree: use dzl_set_weak_pointer()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] tree: use dzl_set_weak_pointer()
- Date: Tue, 5 Dec 2017 01:57:22 +0000 (UTC)
commit d0d3dc546f3f90c13f2c954c288ca6b70750bcce
Author: Christian Hergert <chergert redhat com>
Date: Mon Dec 4 17:49:04 2017 -0800
tree: use dzl_set_weak_pointer()
This switches some old code to use the weak pointer helpers
that we have in libdazzle.
src/tree/dzl-tree-builder.c | 25 +++--------------------
src/tree/dzl-tree-node.c | 45 ++++--------------------------------------
2 files changed, 9 insertions(+), 61 deletions(-)
---
diff --git a/src/tree/dzl-tree-builder.c b/src/tree/dzl-tree-builder.c
index 7081770..c7fa463 100644
--- a/src/tree/dzl-tree-builder.c
+++ b/src/tree/dzl-tree-builder.c
@@ -22,6 +22,7 @@
#include "tree/dzl-tree.h"
#include "tree/dzl-tree-builder.h"
+#include "util/dzl-macros.h"
typedef struct
{
@@ -158,22 +159,8 @@ _dzl_tree_builder_set_tree (DzlTreeBuilder *builder,
g_return_if_fail (priv->tree == NULL || DZL_IS_TREE (priv->tree));
g_return_if_fail (DZL_IS_TREE (tree));
- if (priv->tree != tree)
- {
- if (priv->tree != NULL)
- {
- g_object_remove_weak_pointer (G_OBJECT (priv->tree), (gpointer *)&priv->tree);
- priv->tree = NULL;
- }
-
- if (tree != NULL)
- {
- priv->tree = tree;
- g_object_add_weak_pointer (G_OBJECT (priv->tree), (gpointer *)&priv->tree);
- }
-
- g_object_notify_by_pspec (G_OBJECT (builder), properties [PROP_TREE]);
- }
+ if (dzl_set_weak_pointer (&priv->tree, tree))
+ g_object_notify_by_pspec (G_OBJECT (builder), properties [PROP_TREE]);
}
/**
@@ -200,11 +187,7 @@ dzl_tree_builder_finalize (GObject *object)
DzlTreeBuilder *builder = DZL_TREE_BUILDER (object);
DzlTreeBuilderPrivate *priv = dzl_tree_builder_get_instance_private (builder);
- if (priv->tree)
- {
- g_object_remove_weak_pointer (G_OBJECT (priv->tree), (gpointer *)&priv->tree);
- priv->tree = NULL;
- }
+ dzl_clear_weak_pointer (&priv->tree);
G_OBJECT_CLASS (dzl_tree_builder_parent_class)->finalize (object);
}
diff --git a/src/tree/dzl-tree-node.c b/src/tree/dzl-tree-node.c
index 695b4e0..ea9d064 100644
--- a/src/tree/dzl-tree-node.c
+++ b/src/tree/dzl-tree-node.c
@@ -23,6 +23,7 @@
#include "tree/dzl-tree.h"
#include "tree/dzl-tree-node.h"
#include "tree/dzl-tree-private.h"
+#include "util/dzl-macros.h"
struct _DzlTreeNode
{
@@ -114,20 +115,7 @@ _dzl_tree_node_set_tree (DzlTreeNode *node,
g_return_if_fail (DZL_IS_TREE_NODE (node));
g_return_if_fail (!tree || DZL_IS_TREE (tree));
- if (node->tree != tree)
- {
- if (node->tree != NULL)
- {
- g_object_remove_weak_pointer (G_OBJECT (node->tree), (gpointer *)&node->tree);
- node->tree = NULL;
- }
-
- if (tree != NULL)
- {
- node->tree = tree;
- g_object_add_weak_pointer (G_OBJECT (node->tree), (gpointer *)&node->tree);
- }
- }
+ dzl_set_weak_pointer (&node->tree, tree);
}
/**
@@ -496,20 +484,7 @@ _dzl_tree_node_set_parent (DzlTreeNode *node,
g_return_if_fail (node->parent == NULL);
g_return_if_fail (!parent || DZL_IS_TREE_NODE (parent));
- if (parent != node->parent)
- {
- if (node->parent != NULL)
- {
- g_object_remove_weak_pointer (G_OBJECT (node->parent), (gpointer *)&node->parent);
- node->parent = NULL;
- }
-
- if (parent != NULL)
- {
- node->parent = parent;
- g_object_add_weak_pointer (G_OBJECT (node->parent), (gpointer *)&node->parent);
- }
- }
+ dzl_set_weak_pointer (&node->parent, parent);
}
const gchar *
@@ -687,18 +662,8 @@ dzl_tree_node_finalize (GObject *object)
g_clear_object (&self->item);
g_clear_pointer (&self->text, g_free);
- if (self->tree)
- {
- g_object_remove_weak_pointer (G_OBJECT (self->tree), (gpointer *)&self->tree);
- self->tree = NULL;
- }
-
- if (self->parent)
- {
- g_object_remove_weak_pointer (G_OBJECT (self->parent),
- (gpointer *)&self->parent);
- self->parent = NULL;
- }
+ dzl_clear_weak_pointer (&self->tree);
+ dzl_clear_weak_pointer (&self->parent);
G_OBJECT_CLASS (dzl_tree_node_parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]