[epiphany/mcatanzaro/pages-view] pages-view: simplify weak ref usage




commit 405e1f21b2c6292d31a7c8135f0959fbf308f73e
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Tue May 4 15:15:06 2021 -0500

    pages-view: simplify weak ref usage
    
    This code does not need to be threadsafe, so we can simplify it by using
    g_object_add_weak_pointer() and g_clear_weak_pointer().

 src/ephy-pages-view.c | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)
---
diff --git a/src/ephy-pages-view.c b/src/ephy-pages-view.c
index c4f565e11..d69ddc989 100644
--- a/src/ephy-pages-view.c
+++ b/src/ephy-pages-view.c
@@ -38,21 +38,6 @@ struct _EphyPagesView {
 
 G_DEFINE_TYPE (EphyPagesView, ephy_pages_view, GTK_TYPE_BOX)
 
-static void
-drop_tab_view (EphyPagesView *self)
-{
-  self->tab_view = NULL;
-}
-
-static void
-release_tab_view (EphyPagesView *self)
-{
-  if (self->tab_view) {
-    g_object_weak_unref (G_OBJECT (self->tab_view), (GWeakNotify)drop_tab_view, self);
-    drop_tab_view (self);
-  }
-}
-
 static void
 row_activated_cb (EphyPagesView *self,
                   EphyPageRow   *row)
@@ -110,7 +95,7 @@ ephy_pages_view_dispose (GObject *object)
 {
   EphyPagesView *self = EPHY_PAGES_VIEW (object);
 
-  release_tab_view (self);
+  g_clear_weak_pointer (&self->tab_view);
 
   G_OBJECT_CLASS (ephy_pages_view_parent_class)->dispose (object);
 }
@@ -154,13 +139,12 @@ ephy_pages_view_set_tab_view (EphyPagesView *self,
 {
   g_assert (EPHY_IS_PAGES_VIEW (self));
 
-  if (self->tab_view)
-    release_tab_view (self);
+  g_clear_weak_pointer (&self->tab_view);
 
   if (!tab_view)
     return;
 
-  g_object_weak_ref (G_OBJECT (tab_view), (GWeakNotify)drop_tab_view, self);
+  g_object_add_weak_pointer (G_OBJECT (tab_view), (gpointer*)&self->tab_view);
   self->tab_view = tab_view;
 
   self->model = hdy_tab_view_get_pages (ephy_tab_view_get_tab_view (tab_view));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]