From e152d25ac06529792c2822d73a40b91e283ba80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Thu, 6 Feb 2020 08:17:51 +0100 Subject: [PATCH] widget: Speed up verify_invariants() Hide the expensive GTK_IS_ROOT() checks behind the cheaper realized, mapped, etc. checks. This way we only check for the widget being a root if the invariant does not hold. This gets pop_verify_invariants() from 16% to 6% when running the scrolling benchmark in the widget-factory. --- gtk/gtkwidget.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 65afc651cd..79554ff3af 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -6332,12 +6332,9 @@ gtk_widget_verify_invariants (GtkWidget *widget) g_warning ("%s %p is mapped but not visible", gtk_widget_get_name (widget), widget); - if (!GTK_IS_ROOT (widget)) - { - if (!priv->child_visible) - g_warning ("%s %p is mapped but not child_visible", - gtk_widget_get_name (widget), widget); - } + if (!priv->child_visible && !GTK_IS_ROOT (widget)) + g_warning ("%s %p is mapped but not child_visible", + gtk_widget_get_name (widget), widget); } else { @@ -6380,14 +6377,12 @@ gtk_widget_verify_invariants (GtkWidget *widget) G_OBJECT_TYPE_NAME (widget), widget); #endif } - else if (!GTK_IS_ROOT (widget)) + else if (priv->realized && !GTK_IS_ROOT (widget)) { /* No parent or parent not realized on non-toplevel implies... */ - - if (priv->realized) - g_warning ("%s %p is not realized but child %s %p is realized", - parent ? gtk_widget_get_name (parent) : "no parent", parent, - gtk_widget_get_name (widget), widget); + g_warning ("%s %p is not realized but child %s %p is realized", + parent ? gtk_widget_get_name (parent) : "no parent", parent, + gtk_widget_get_name (widget), widget); } if (parent && @@ -6402,17 +6397,15 @@ gtk_widget_verify_invariants (GtkWidget *widget) gtk_widget_get_name (parent), parent, gtk_widget_get_name (widget), widget); } - else if (!GTK_IS_ROOT (widget)) + else if (priv->mapped && !GTK_IS_ROOT (widget)) { /* No parent or parent not mapped on non-toplevel implies... */ - - if (priv->mapped) - g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d", - gtk_widget_get_name (widget), widget, - priv->visible, - priv->child_visible, - parent ? gtk_widget_get_name (parent) : "no parent", parent, - parent ? parent->priv->mapped : FALSE); + g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d", + gtk_widget_get_name (widget), widget, + priv->visible, + priv->child_visible, + parent ? gtk_widget_get_name (parent) : "no parent", parent, + parent ? parent->priv->mapped : FALSE); } }