[gtk/class-cast-avoidance] Cut down on type-checking overhead




commit 937ccf152b23169ce68987e31161938550381387
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue May 17 07:52:47 2022 -0400

    Cut down on type-checking overhead
    
    We *know* what the parent class is. There is
    no point in checking every time we want to
    chain up. We only do this because the
    foo_parent_class that the G_DEFINE_TYPE macro
    provides for us is a generic pointer. And that
    is just because we don't have the C name for
    the parent type available there.
    
    Just cast things, and avoid taking type system
    locks.

 gtk/gtkcolumnlistitemfactory.c | 19 ++++++++++++-------
 gtk/gtklistitem.c              |  4 +++-
 gtk/gtklistitemfactory.c       |  2 +-
 gtk/gtklistitemwidget.c        | 11 +++++++----
 4 files changed, 23 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtkcolumnlistitemfactory.c b/gtk/gtkcolumnlistitemfactory.c
index e6188cb4d4..2e887c0b5a 100644
--- a/gtk/gtkcolumnlistitemfactory.c
+++ b/gtk/gtkcolumnlistitemfactory.c
@@ -41,6 +41,9 @@ struct _GtkColumnListItemFactoryClass
 
 G_DEFINE_TYPE (GtkColumnListItemFactory, gtk_column_list_item_factory, GTK_TYPE_LIST_ITEM_FACTORY)
 
+#define ancestor_class(T_N) ((T_N##Class *)gtk_column_list_item_factory_parent_class)
+#define parent_class ancestor_class(GtkListItemFactory)
+
 static void
 gtk_column_list_item_factory_setup (GtkListItemFactory *factory,
                                     GtkListItemWidget  *widget,
@@ -54,7 +57,7 @@ gtk_column_list_item_factory_setup (GtkListItemFactory *factory,
   gtk_widget_set_layout_manager (GTK_WIDGET (widget),
                                  gtk_column_view_layout_new (self->view));
 
-  GTK_LIST_ITEM_FACTORY_CLASS (gtk_column_list_item_factory_parent_class)->setup (factory, widget, 
list_item);
+  parent_class->setup (factory, widget, list_item);
 
   columns = gtk_column_view_get_columns (self->view);
 
@@ -76,13 +79,14 @@ gtk_column_list_item_factory_teardown (GtkListItemFactory *factory,
                                        GtkListItemWidget  *widget,
                                        GtkListItem        *list_item)
 {
+  GtkWidget *w = GTK_WIDGET (widget);
   GtkWidget *child;
 
-  GTK_LIST_ITEM_FACTORY_CLASS (gtk_column_list_item_factory_parent_class)->teardown (factory, widget, 
list_item);
+  parent_class->teardown (factory, widget, list_item);
 
-  while ((child = gtk_widget_get_first_child (GTK_WIDGET (widget))))
+  while ((child = gtk_widget_get_first_child (w)))
     {
-      gtk_list_item_widget_remove_child (GTK_LIST_ITEM_WIDGET (widget), child);
+      gtk_list_item_widget_remove_child (widget, child);
     }
 }
 
@@ -94,11 +98,12 @@ gtk_column_list_item_factory_update (GtkListItemFactory *factory,
                                      gpointer            item,
                                      gboolean            selected)
 {
+  GtkWidget *w = GTK_WIDGET (widget);
   GtkWidget *child;
 
-  GTK_LIST_ITEM_FACTORY_CLASS (gtk_column_list_item_factory_parent_class)->update (factory, widget, 
list_item, position, item, selected);
+  parent_class->update (factory, widget, list_item, position, item, selected);
 
-  for (child = gtk_widget_get_first_child (GTK_WIDGET (widget));
+  for (child = gtk_widget_get_first_child (w);
        child;
        child = gtk_widget_get_next_sibling (child))
     {
@@ -142,7 +147,7 @@ gtk_column_list_item_factory_add_column (GtkColumnListItemFactory *factory,
   GtkWidget *cell;
 
   cell = gtk_column_view_cell_new (column);
-  gtk_list_item_widget_add_child (GTK_LIST_ITEM_WIDGET (list_item), GTK_WIDGET (cell));
+  gtk_list_item_widget_add_child (list_item, cell);
   gtk_list_item_widget_update (GTK_LIST_ITEM_WIDGET (cell),
                                gtk_list_item_widget_get_position (list_item),
                                gtk_list_item_widget_get_item (list_item),
diff --git a/gtk/gtklistitem.c b/gtk/gtklistitem.c
index df818be758..099604247b 100644
--- a/gtk/gtklistitem.c
+++ b/gtk/gtklistitem.c
@@ -62,6 +62,8 @@ enum
 
 G_DEFINE_TYPE (GtkListItem, gtk_list_item, G_TYPE_OBJECT)
 
+#define parent_class ((GObjectClass *)gtk_list_item_parent_class)
+
 static GParamSpec *properties[N_PROPS] = { NULL, };
 
 static void
@@ -72,7 +74,7 @@ gtk_list_item_dispose (GObject *object)
   g_assert (self->owner == NULL); /* would hold a reference */
   g_clear_object (&self->child);
 
-  G_OBJECT_CLASS (gtk_list_item_parent_class)->dispose (object);
+  parent_class->dispose (object);
 }
 
 static void
diff --git a/gtk/gtklistitemfactory.c b/gtk/gtklistitemfactory.c
index 48383f29de..d3ae7ca130 100644
--- a/gtk/gtklistitemfactory.c
+++ b/gtk/gtklistitemfactory.c
@@ -96,7 +96,7 @@ gtk_list_item_factory_default_teardown (GtkListItemFactory *self,
   gtk_list_item_set_child (list_item, NULL);
 }
 
-static void                  
+static void
 gtk_list_item_factory_default_update (GtkListItemFactory *self,
                                       GtkListItemWidget  *widget,
                                       GtkListItem        *list_item,
diff --git a/gtk/gtklistitemwidget.c b/gtk/gtklistitemwidget.c
index fc407fbd83..703db93968 100644
--- a/gtk/gtklistitemwidget.c
+++ b/gtk/gtklistitemwidget.c
@@ -62,6 +62,9 @@ enum
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkListItemWidget, gtk_list_item_widget, GTK_TYPE_WIDGET)
 
+#define ancestor_class(T_N) ((T_N##Class *)gtk_list_item_widget_parent_class)
+#define parent_class ancestor_class(GtkWidget)
+
 static GParamSpec *properties[N_PROPS] = { NULL, };
 static guint signals[LAST_SIGNAL] = { 0 };
 
@@ -137,7 +140,7 @@ gtk_list_item_widget_grab_focus (GtkWidget *widget)
       !priv->list_item->selectable)
     return FALSE;
 
-  return GTK_WIDGET_CLASS (gtk_list_item_widget_parent_class)->grab_focus (widget);
+  return parent_class->grab_focus (widget);
 }
 
 static void
@@ -146,7 +149,7 @@ gtk_list_item_widget_root (GtkWidget *widget)
   GtkListItemWidget *self = GTK_LIST_ITEM_WIDGET (widget);
   GtkListItemWidgetPrivate *priv = gtk_list_item_widget_get_instance_private (self);
 
-  GTK_WIDGET_CLASS (gtk_list_item_widget_parent_class)->root (widget);
+  parent_class->root (widget);
 
   if (priv->factory)
     gtk_list_item_factory_setup (priv->factory, self);
@@ -158,7 +161,7 @@ gtk_list_item_widget_unroot (GtkWidget *widget)
   GtkListItemWidget *self = GTK_LIST_ITEM_WIDGET (widget);
   GtkListItemWidgetPrivate *priv = gtk_list_item_widget_get_instance_private (self);
 
-  GTK_WIDGET_CLASS (gtk_list_item_widget_parent_class)->unroot (widget);
+  parent_class->unroot (widget);
 
   if (priv->list_item)
       gtk_list_item_factory_teardown (priv->factory, self);
@@ -199,7 +202,7 @@ gtk_list_item_widget_dispose (GObject *object)
   g_clear_object (&priv->item);
   g_clear_object (&priv->factory);
 
-  G_OBJECT_CLASS (gtk_list_item_widget_parent_class)->dispose (object);
+  ancestor_class(GObject)->dispose (object);
 }
 
 static void


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