From 585dadf575aa047e9ef536bc5b26b60911edebb1 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 28 Apr 2024 12:08:15 -0400 Subject: [PATCH] Small optimization Avoid copying a potentially large blob more than necessary. --- gtk/gdktextureutils.c | 49 ++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/gtk/gdktextureutils.c b/gtk/gdktextureutils.c index 96aed7133c..721566ff1b 100644 --- a/gtk/gdktextureutils.c +++ b/gtk/gdktextureutils.c @@ -199,6 +199,7 @@ _gdk_pixbuf_new_from_resource_at_scale (const char *resource_path, static GdkPixbuf * load_symbolic_svg (const char *escaped_file_data, + gsize len, int width, int height, const char *icon_width_str, @@ -214,30 +215,31 @@ load_symbolic_svg (const char *escaped_file_data, char *data; data = g_strconcat ("\n" - "\n" - " \n" - " \n" - "", + "" + "" + "", strlen ("\"/>"), NULL); pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream, width, height, TRUE, NULL, error); g_object_unref (stream); @@ -300,6 +302,7 @@ gtk_make_symbolic_pixbuf_from_data (const char *file_data, int plane; int icon_width, icon_height; char *escaped_file_data; + gsize len; /* Fetch size from the original icon */ GInputStream *stream = g_memory_input_stream_new_from_data (file_data, file_len, NULL); @@ -315,6 +318,8 @@ gtk_make_symbolic_pixbuf_from_data (const char *file_data, g_object_unref (reference); escaped_file_data = g_base64_encode ((guchar *) file_data, file_len); + len = strlen (escaped_file_data); + icon_width_str = g_strdup_printf ("%d", icon_width); icon_height_str = g_strdup_printf ("%d", icon_height); @@ -337,7 +342,7 @@ gtk_make_symbolic_pixbuf_from_data (const char *file_data, * channels, with the color of the fg being implicitly * the "rest", as all color fractions should add up to 1. */ - loaded = load_symbolic_svg (escaped_file_data, width, height, + loaded = load_symbolic_svg (escaped_file_data, len, width, height, icon_width_str, icon_height_str, g_string,