icontheme: Optimize suffix_from_name

We call this function a lot, so avoid repeated strlen() calls on @name
and the different suffixes.
This commit is contained in:
Timm Bäder 2019-09-01 10:20:00 +02:00
parent b65d9ca955
commit 38b4a2a8e2

View File

@ -2680,24 +2680,30 @@ string_from_suffix (IconSuffix suffix)
} }
} }
static IconSuffix static inline IconSuffix
suffix_from_name (const gchar *name) suffix_from_name (const gchar *name)
{ {
IconSuffix retval = ICON_SUFFIX_NONE; const gsize name_len = strlen (name);
if (name != NULL) if (name_len > 4)
{ {
if (g_str_has_suffix (name, ".symbolic.png")) if (name_len > strlen (".symbolic.png"))
retval = ICON_SUFFIX_SYMBOLIC_PNG; {
else if (g_str_has_suffix (name, ".png")) if (strcmp (name + name_len - strlen (".symbolic.png"), ".symbolic.png") == 0)
retval = ICON_SUFFIX_PNG; return ICON_SUFFIX_SYMBOLIC_PNG;
else if (g_str_has_suffix (name, ".svg")) }
retval = ICON_SUFFIX_SVG;
else if (g_str_has_suffix (name, ".xpm")) if (strcmp (name + name_len - strlen (".png"), ".png") == 0)
retval = ICON_SUFFIX_XPM; return ICON_SUFFIX_PNG;
if (strcmp (name + name_len - strlen (".svg"), ".svg") == 0)
return ICON_SUFFIX_SVG;
if (strcmp (name + name_len - strlen (".xpm"), ".xpm") == 0)
return ICON_SUFFIX_XPM;
} }
return retval; return ICON_SUFFIX_NONE;
} }
static IconSuffix static IconSuffix