diff options
author | Timm Bäder <mail@baedert.org> | 2021-01-03 08:45:30 +0100 |
---|---|---|
committer | Timm Bäder <mail@baedert.org> | 2021-01-03 11:01:29 +0100 |
commit | 699adb0b1063d71d226e99a4dd387aca8a31cb9d (patch) | |
tree | b4dd350cc5a93a28626b741110d4b2cd16b3f34c | |
parent | c91b5eaa41328ad8903caba8201b48c12baa1cb1 (diff) | |
download | gtk+-699adb0b1063d71d226e99a4dd387aca8a31cb9d.tar.gz |
widget: Refactor gtk_widget_class_set_template()
Don't call gbytes_get_data/get_size so often and exit early if the given
bytes is already precompiled.
-rw-r--r-- | gtk/gtkwidget.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 98ff2a01e4..239f7735e8 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -10852,35 +10852,36 @@ out: * in the widget’s instance initializer. */ void -gtk_widget_class_set_template (GtkWidgetClass *widget_class, - GBytes *template_bytes) +gtk_widget_class_set_template (GtkWidgetClass *widget_class, + GBytes *template_bytes) { + GError *error = NULL; GBytes *data = NULL; + gconstpointer bytes_data; + gsize bytes_size; g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class)); g_return_if_fail (widget_class->priv->template == NULL); g_return_if_fail (template_bytes != NULL); widget_class->priv->template = g_slice_new0 (GtkWidgetTemplate); + bytes_data = g_bytes_get_data (template_bytes, &bytes_size); - if (!_gtk_buildable_parser_is_precompiled (g_bytes_get_data (template_bytes, NULL), g_bytes_get_size (template_bytes))) + if (_gtk_buildable_parser_is_precompiled (bytes_data, bytes_size)) { - GError *error = NULL; + widget_class->priv->template->data = g_bytes_ref (template_bytes); + return; + } - data = _gtk_buildable_parser_precompile (g_bytes_get_data (template_bytes, NULL), - g_bytes_get_size (template_bytes), - &error); - if (data == NULL) - { - g_warning ("Failed to precompile template for class %s: %s", G_OBJECT_CLASS_NAME (widget_class), error->message); - g_error_free (error); - } + data = _gtk_buildable_parser_precompile (bytes_data, bytes_size, &error); + if (data == NULL) + { + g_warning ("Failed to precompile template for class %s: %s", G_OBJECT_CLASS_NAME (widget_class), error->message); + g_error_free (error); + return; } - if (data) - widget_class->priv->template->data = data; - else - widget_class->priv->template->data = g_bytes_ref (template_bytes); + widget_class->priv->template->data = data; } /** |