widget: Add static inline version of gtk_widget_display()

Due to the few type checks in gtk_widget_get_display(), it was the
slowest part of a call to gtk_widget_query_size_for_orientation if the
in case of a cache hit.
This commit is contained in:
Timm Bäder 2018-04-21 17:03:31 +02:00
parent 1a24a360bd
commit c3e02b2b22
2 changed files with 19 additions and 13 deletions

View File

@ -7763,21 +7763,9 @@ gtk_widget_get_scale_factor (GtkWidget *widget)
GdkDisplay*
gtk_widget_get_display (GtkWidget *widget)
{
GtkWidget *toplevel;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
toplevel = _gtk_widget_get_toplevel (widget);
if (_gtk_widget_is_toplevel (toplevel))
{
if (GTK_IS_WINDOW (toplevel))
return gtk_window_get_display (GTK_WINDOW (toplevel));
else if (GTK_IS_INVISIBLE (toplevel))
return gtk_invisible_get_display (GTK_INVISIBLE (widget));
}
return gdk_display_get_default ();
return _gtk_widget_get_display (widget);
}
/**

View File

@ -32,6 +32,8 @@
#include "gtkcsstypesprivate.h"
#include "gtkeventcontroller.h"
#include "gtksizerequestcacheprivate.h"
#include "gtkwindowprivate.h"
#include "gtkinvisible.h"
G_BEGIN_DECLS
@ -412,6 +414,22 @@ _gtk_widget_get_toplevel (GtkWidget *widget)
return widget;
}
static inline GdkDisplay *
_gtk_widget_get_display (GtkWidget *widget)
{
GtkWidget *toplevel = _gtk_widget_get_toplevel (widget);
if (_gtk_widget_is_toplevel (toplevel))
{
if (GTK_IS_WINDOW (toplevel))
return gtk_window_get_display (GTK_WINDOW (toplevel));
else if (GTK_IS_INVISIBLE (toplevel))
return gtk_invisible_get_display (GTK_INVISIBLE (widget));
}
return gdk_display_get_default ();
}
static inline GtkStyleContext *
_gtk_widget_get_style_context (GtkWidget *widget)
{