[Xfce4-commits] <garcon:master> Optimize the garcon_menu_item_get_show_in_environment function.

Nick Schermer nick at xfce.org
Mon Aug 17 18:16:03 CEST 2009


Updating branch refs/heads/master
         to 6a867e6cddd4e7b48054475e57988af693c477da (commit)
       from 389d7c4cf3c04d9c563cada7f09d710adbc5261d (commit)

commit 6a867e6cddd4e7b48054475e57988af693c477da
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Aug 17 17:29:55 2009 +0200

    Optimize the garcon_menu_item_get_show_in_environment function.

 garcon/garcon-menu-item.c |   42 ++++++++++++++++--------------------------
 1 files changed, 16 insertions(+), 26 deletions(-)

diff --git a/garcon/garcon-menu-item.c b/garcon/garcon-menu-item.c
index 9480428..3259a82 100644
--- a/garcon/garcon-menu-item.c
+++ b/garcon/garcon-menu-item.c
@@ -1112,8 +1112,6 @@ gboolean
 garcon_menu_item_get_show_in_environment (GarconMenuItem *item)
 {
   const gchar *env;
-  gboolean     show = TRUE;
-  gboolean     included;
   guint        i;
 
   g_return_val_if_fail (GARCON_IS_MENU_ITEM (item), FALSE);
@@ -1121,43 +1119,35 @@ garcon_menu_item_get_show_in_environment (GarconMenuItem *item)
   /* Determine current environment */
   env = garcon_get_environment ();
 
-  /* If no environment has been set, the menu item is displayed no matter what
+  /* If no environment has been set, the menu is displayed no matter what
    * OnlyShowIn or NotShowIn contain */
   if (G_UNLIKELY (env == NULL))
     return TRUE;
 
-  /* Check if we have an OnlyShowIn OR a NotShowIn list (only one of them will be
-   * there, according to the desktop entry specification) */
+  /* According to the spec there is either a OnlyShowIn or a NotShowIn list */
   if (G_UNLIKELY (item->priv->only_show_in != NULL))
     {
-      /* Determine whether our environment is included in this list */
-      included = FALSE;
-      for (i = 0; i < g_strv_length (item->priv->only_show_in); ++i)
-        {
-          if (G_UNLIKELY (g_utf8_collate (item->priv->only_show_in[i], env) == 0))
-            included = TRUE;
-        }
+      /* Check if your environemnt is in OnlyShowIn list */
+      for (i = 0; item->priv->only_show_in[i] != NULL; i++)
+        if (g_utf8_collate (item->priv->only_show_in[i], env) == 0)
+          return TRUE;
 
-      /* If it's not, don't show the menu item */
-      if (G_LIKELY (!included))
-        show = FALSE;
+      /* Not in the list, hide it */
+      return FALSE;
     }
   else if (G_UNLIKELY (item->priv->not_show_in != NULL))
     {
-      /* Determine whether our environment is included in this list */
-      included = FALSE;
-      for (i = 0; i < g_strv_length (item->priv->not_show_in); ++i)
-        {
-          if (G_UNLIKELY (g_utf8_collate (item->priv->not_show_in[i], env) == 0))
-            included = TRUE;
-        }
+      /* Check if your environemnt is in NotShowIn list */
+      for (i = 0; item->priv->not_show_in[i] != NULL; i++)
+        if (g_utf8_collate (item->priv->not_show_in[i], env) == 0)
+          return FALSE;
 
-      /* If it is, hide the menu item */
-      if (G_UNLIKELY (included))
-        show = FALSE;
+      /* Not in the list, show it */
+      return TRUE;
     }
 
-  return show;
+  /* No list, show it */
+  return TRUE;
 }
 
 



More information about the Xfce4-commits mailing list