[gtk+/gtk-3-22] css: avoid copying resource data
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-3-22] css: avoid copying resource data
- Date: Mon, 13 Nov 2017 04:04:20 +0000 (UTC)
commit b654130bd7d392dec5b4775991e59ac0f0990ff2
Author: Christian Hergert <chergert redhat com>
Date: Sun Nov 12 19:34:46 2017 -0800
css: avoid copying resource data
To avoid copying data from gresources to the heap, we can use
the newly added gtk_file_load_bytes(). That function will check
for resource:// URIs and access their internal data directly.
Other URI schemes will read the contents into memory and return
a GBytes as normal.
https://bugzilla.gnome.org/show_bug.cgi?id=790270
gtk/gtkcssprovider.c | 13 +++++++------
1 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index fecbace..aedbf1f 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -44,6 +44,7 @@
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtkintl.h"
+#include "gtkutilsprivate.h"
#include "gtkversion.h"
/**
@@ -1722,9 +1723,9 @@ gtk_css_provider_load_internal (GtkCssProvider *css_provider,
const char *text,
GError **error)
{
+ GBytes *free_bytes = NULL;
GtkCssScanner *scanner;
gulong error_handler;
- char *free_data = NULL;
if (error)
error_handler = g_signal_connect (css_provider,
@@ -1738,11 +1739,11 @@ gtk_css_provider_load_internal (GtkCssProvider *css_provider,
{
GError *load_error = NULL;
- if (g_file_load_contents (file, NULL,
- &free_data, NULL,
- NULL, &load_error))
+ free_bytes = gtk_file_load_bytes (file, NULL, &load_error);
+
+ if (free_bytes != NULL)
{
- text = free_data;
+ text = g_bytes_get_data (free_bytes, NULL);
}
else
{
@@ -1791,7 +1792,7 @@ gtk_css_provider_load_internal (GtkCssProvider *css_provider,
gtk_css_provider_postprocess (css_provider);
}
- g_free (free_data);
+ g_bytes_unref (free_bytes);
if (error)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]