[gtk/wip/baedert/icontheme: 36/41] icontheme: Avoid some more strlen calls



commit fbe438ead430e335b1c3221ab5a81ea2e095b1f6
Author: Timm Bäder <mail baedert org>
Date:   Tue May 21 14:32:47 2019 +0200

    icontheme: Avoid some more strlen calls
    
    Replace the two loops here with one. Call strlen() on the icon name once
    and reuse that value.

 gtk/gtkicontheme.c | 42 ++++++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 18 deletions(-)
---
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index d41ed738aa..d6770d5e39 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -1901,18 +1901,21 @@ choose_icon (GtkIconTheme       *icon_theme,
 
   if ((flags & GTK_ICON_LOOKUP_FORCE_REGULAR) && has_symbolic)
     {
-      new_names = g_ptr_array_new_full (2 * n_icon_names, g_free);
+      new_names = g_ptr_array_new_full (4 * n_icon_names, g_free);
+
       for (i = 0; icon_names[i]; i++)
         {
-          if (icon_name_is_symbolic (icon_names[i], -1))
-            icon_name_list_add_icon (new_names, dir_suffix, g_strndup (icon_names[i], strlen (icon_names[i]) 
- strlen ("-symbolic")));
+          int icon_name_len = strlen (icon_names[i]);
+
+          if (icon_name_is_symbolic (icon_names[i], icon_name_len))
+            {
+              icon_name_list_add_icon (new_names, dir_suffix, g_strndup (icon_names[i], icon_name_len - 
strlen ("-symbolic")));
+              icon_name_list_add_icon (new_names, dir_suffix, g_strdup (icon_names[i]));
+            }
           else
-            icon_name_list_add_icon (new_names, dir_suffix, g_strdup (icon_names[i]));
-        }
-      for (i = 0; icon_names[i]; i++)
-        {
-          if (icon_name_is_symbolic (icon_names[i], -1))
-            icon_name_list_add_icon (new_names, dir_suffix, g_strdup (icon_names[i]));
+            {
+              icon_name_list_add_icon (new_names, dir_suffix, g_strdup (icon_names[i]));
+            }
         }
 
       icon_info = real_choose_icon (icon_theme,
@@ -1926,18 +1929,21 @@ choose_icon (GtkIconTheme       *icon_theme,
     }
   else if ((flags & GTK_ICON_LOOKUP_FORCE_SYMBOLIC) && has_regular)
     {
-      new_names = g_ptr_array_new_full (2 * n_icon_names, g_free);
+      new_names = g_ptr_array_new_full (4 * n_icon_names, g_free);
+
       for (i = 0; icon_names[i]; i++)
         {
-          if (!icon_name_is_symbolic (icon_names[i], -1))
-            icon_name_list_add_icon (new_names, dir_suffix, g_strconcat (icon_names[i], "-symbolic", NULL));
+          int icon_name_len = strlen (icon_names[i]);
+
+          if (!icon_name_is_symbolic (icon_names[i], icon_name_len))
+            {
+              icon_name_list_add_icon (new_names, dir_suffix, g_strconcat (icon_names[i], "-symbolic", 
NULL));
+              icon_name_list_add_icon (new_names, dir_suffix, g_strdup (icon_names[i]));
+            }
           else
-            icon_name_list_add_icon (new_names, dir_suffix, g_strdup (icon_names[i]));
-        }
-      for (i = 0; icon_names[i]; i++)
-        {
-          if (!icon_name_is_symbolic (icon_names[i], -1))
-            icon_name_list_add_icon (new_names, dir_suffix, g_strdup (icon_names[i]));
+            {
+              icon_name_list_add_icon (new_names, dir_suffix, g_strdup (icon_names[i]));
+            }
         }
 
       icon_info = real_choose_icon (icon_theme,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]