[gimp] app: reduce indentation depth in gimp_plug_in_manager_search_directory()



commit ea7f1ba0242acaaecb9959bfd8cb4e848d467e22
Author: Michael Natterer <mitch gimp org>
Date:   Fri May 26 18:47:13 2017 +0200

    app: reduce indentation depth in gimp_plug_in_manager_search_directory()
    
    by removing one if() level each from the nested loops. Instead,
    continue the loop early if the file is hidden. And plug a memory leak.

 app/plug-in/gimppluginmanager-restore.c |  128 +++++++++++++++++--------------
 1 files changed, 71 insertions(+), 57 deletions(-)
---
diff --git a/app/plug-in/gimppluginmanager-restore.c b/app/plug-in/gimppluginmanager-restore.c
index 0f4c58a..5224788 100644
--- a/app/plug-in/gimppluginmanager-restore.c
+++ b/app/plug-in/gimppluginmanager-restore.c
@@ -258,84 +258,98 @@ gimp_plug_in_manager_search_directory (GimpPlugInManager *manager,
                                           G_FILE_ATTRIBUTE_TIME_MODIFIED,
                                           G_FILE_QUERY_INFO_NONE,
                                           NULL, NULL);
-
   if (enumerator)
     {
       GFileInfo *info;
 
       while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)))
         {
-         if (! g_file_info_get_is_hidden (info))
+          GFile *child;
+
+          if (g_file_info_get_is_hidden (info))
             {
-              GFile *child = g_file_enumerator_get_child (enumerator, info);
+              g_object_unref (info);
+              continue;
+            }
 
-              if (gimp_file_is_executable (child))
-                {
-                  guint64 mtime;
+          child = g_file_enumerator_get_child (enumerator, info);
 
-                  mtime = g_file_info_get_attribute_uint64 (info,
-                                                            G_FILE_ATTRIBUTE_TIME_MODIFIED);
+          if (gimp_file_is_executable (child))
+            {
+              guint64 mtime;
 
-                  gimp_plug_in_manager_add_from_file (manager, child, mtime);
-                }
-              else if (g_file_query_file_type (child,
-                                               G_FILE_CREATE_NONE,
-                                               NULL) == G_FILE_TYPE_DIRECTORY)
+              mtime = g_file_info_get_attribute_uint64 (info,
+                                                        G_FILE_ATTRIBUTE_TIME_MODIFIED);
+
+              gimp_plug_in_manager_add_from_file (manager, child, mtime);
+            }
+          else if (g_file_query_file_type (child,
+                                           G_FILE_CREATE_NONE,
+                                           NULL) == G_FILE_TYPE_DIRECTORY)
+            {
+              /* Search in subdirectory the first executable file with
+               * the same name as the directory (except extension).
+               * We don't search recursively, but only at a single
+               * level and assume that there can be only 1 plugin
+               * inside a directory.
+               */
+              GFileEnumerator *enumerator2;
+
+              enumerator2 = g_file_enumerate_children (child,
+                                                       G_FILE_ATTRIBUTE_STANDARD_NAME ","
+                                                       G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
+                                                       G_FILE_ATTRIBUTE_TIME_MODIFIED,
+                                                       G_FILE_QUERY_INFO_NONE,
+                                                       NULL, NULL);
+              if (enumerator2)
                 {
-                  /* Search in subdirectory the first executable file with the
-                   * same name as the directory (except extension).
-                   * We don't search recursively, but only at a single level
-                   * and assume that there can be only 1 plugin inside a
-                   * directory.
-                   */
-                  GFileEnumerator *enumerator2;
-
-                  enumerator2 = g_file_enumerate_children (child,
-                                                           G_FILE_ATTRIBUTE_STANDARD_NAME ","
-                                                           G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
-                                                           G_FILE_ATTRIBUTE_TIME_MODIFIED,
-                                                           G_FILE_QUERY_INFO_NONE,
-                                                           NULL, NULL);
-                  if (enumerator2)
+                  GFileInfo *info2;
+
+                  while ((info2 = g_file_enumerator_next_file (enumerator2, NULL, NULL)))
                     {
-                      GFileInfo *info2;
+                      GFile *child2;
+                      gchar *file_name;
+                      char  *ext;
+
+                      if (g_file_info_get_is_hidden (info2))
+                        {
+                          g_object_unref (info2);
+                          continue;
+                        }
 
-                      while ((info2 = g_file_enumerator_next_file (enumerator2, NULL, NULL)))
+                      child2 = g_file_enumerator_get_child (enumerator2, info2);
+                      file_name = g_strdup (g_file_info_get_name (info2));
+
+                      ext = strrchr (file_name, '.');
+                      if (ext)
+                        *ext = '\0';
+
+                      if (g_strcmp0 (file_name, g_file_info_get_name (info)) == 0 &&
+                          gimp_file_is_executable (child2))
                         {
-                          if (! g_file_info_get_is_hidden (info2))
-                            {
-                              GFile *child2;
-                              gchar *file_name;
-                              char  *ext;
-
-                              child2 = g_file_enumerator_get_child (enumerator2, info2);
-                              file_name = g_strdup (g_file_info_get_name (info2));
-                              ext = strrchr (file_name, '.');
-                              if (ext)
-                                *ext = '\0';
-                              if (g_strcmp0 (file_name, g_file_info_get_name (info)) == 0 &&
-                                  gimp_file_is_executable (child2))
-                                {
-                                  guint64 mtime;
-
-                                  mtime = g_file_info_get_attribute_uint64 (info2,
-                                                                            G_FILE_ATTRIBUTE_TIME_MODIFIED);
-
-                                  gimp_plug_in_manager_add_from_file (manager, child2, mtime);
-                                  break;
-                                }
-                              g_object_unref (child2);
-                              g_free (file_name);
-                            }
+                          guint64 mtime;
+
+                          mtime = g_file_info_get_attribute_uint64 (info2,
+                                                                    G_FILE_ATTRIBUTE_TIME_MODIFIED);
+
+                          gimp_plug_in_manager_add_from_file (manager, child2, mtime);
+
+                          g_free (file_name);
+                          g_object_unref (child2);
                           g_object_unref (info2);
+                          break;
                         }
+
+                      g_free (file_name);
+                      g_object_unref (child2);
+                      g_object_unref (info2);
                     }
+
                   g_object_unref (enumerator2);
                 }
-
-              g_object_unref (child);
             }
 
+          g_object_unref (child);
           g_object_unref (info);
         }
 


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