[gtk/wip/baedert/icontheme: 99/109] icontheme: Avoid a g_strconcat in get_icon_suffix
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/icontheme: 99/109] icontheme: Avoid a g_strconcat in get_icon_suffix
- Date: Mon, 27 May 2019 16:24:25 +0000 (UTC)
commit 53db815f7cb6b0d1952a307dd1cdc02046eb25ea
Author: Timm Bäder <mail baedert org>
Date: Tue May 21 11:25:02 2019 +0200
icontheme: Avoid a g_strconcat in get_icon_suffix
We and up calling this code path over 7000 times on startup.
gtk/gtkicontheme.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index a402dcf38b..480f8a296d 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -2804,7 +2804,7 @@ best_suffix (IconSuffix suffix,
else
return ICON_SUFFIX_NONE;
}
-
+
static IconSuffix
theme_dir_get_icon_suffix (IconThemeDir *dir,
const gchar *icon_name,
@@ -2816,13 +2816,24 @@ theme_dir_get_icon_suffix (IconThemeDir *dir,
{
if (icon_name_is_symbolic (icon_name))
{
+ int icon_name_len = strlen (icon_name);
/* Look for foo-symbolic.symbolic.png, as the cache only stores the ".png" suffix */
- char *icon_name_with_prefix = g_strconcat (icon_name, ".symbolic", NULL);
- symbolic_suffix = (IconSuffix)gtk_icon_cache_get_icon_flags (dir->cache,
- icon_name_with_prefix,
- dir->subdir_index);
- g_free (icon_name_with_prefix);
+ static char icon_name_with_prefix[1024];
+ static const int end_offset = sizeof (icon_name_with_prefix) - strlen (".symbolic") - 1;
+ static gboolean initialized = FALSE;
+ /* We add ".symbolic" at the very end of the string and then prepend the icon name */
+ if (!initialized)
+ {
+ strncpy (icon_name_with_prefix + end_offset, ".symbolic", strlen (".symbolic") + 1);
+ initialized = TRUE;
+ }
+ memcpy (icon_name_with_prefix + end_offset - icon_name_len,
+ icon_name, icon_name_len);
+
+ symbolic_suffix = (IconSuffix)gtk_icon_cache_get_icon_flags (dir->cache,
+ icon_name_with_prefix,
+ dir->subdir_index);
if (symbolic_suffix & ICON_SUFFIX_PNG)
suffix = ICON_SUFFIX_SYMBOLIC_PNG;
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]