Просмотр исходного кода

Optimization of ini files load.

Some ini files (keymaps, skins) are loaded in read-only mode. For those
files, we don't need load and keep comments.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 12 лет назад
Родитель
Сommit
908e747861

+ 2 - 2
lib/filehighlight/ini-file-read.c

@@ -184,9 +184,9 @@ mc_fhl_read_ini_file (mc_fhl_t * fhl, const gchar * filename)
         return FALSE;
 
     if (fhl->config != NULL)
-        return mc_config_read_file (fhl->config, filename, FALSE);
+        return mc_config_read_file (fhl->config, filename, TRUE, FALSE);
 
-    fhl->config = mc_config_init (filename);
+    fhl->config = mc_config_init (filename, TRUE);
     return (fhl->config != NULL);
 }
 

+ 3 - 3
lib/mcconfig.h

@@ -29,8 +29,8 @@ extern mc_config_t *mc_panels_config;
 
 /* mcconfig/common.c: */
 
-mc_config_t *mc_config_init (const gchar *);
-void mc_config_deinit (mc_config_t *);
+mc_config_t *mc_config_init (const gchar * ini_path, gboolean read_only);
+void mc_config_deinit (mc_config_t * mc_config);
 
 gboolean mc_config_del_key (mc_config_t *, const char *, const gchar *);
 gboolean mc_config_del_group (mc_config_t *, const char *);
@@ -38,7 +38,7 @@ gboolean mc_config_del_group (mc_config_t *, const char *);
 gboolean mc_config_has_param (const mc_config_t *, const char *, const gchar *);
 gboolean mc_config_has_group (mc_config_t *, const char *);
 
-gboolean mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path,
+gboolean mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean read_only,
                               gboolean remove_empty);
 
 gboolean mc_config_save_file (mc_config_t * config, GError ** error);

+ 10 - 4
lib/mcconfig/common.c

@@ -102,7 +102,7 @@ mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path,
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
 mc_config_t *
-mc_config_init (const gchar * ini_path)
+mc_config_init (const gchar * ini_path, gboolean read_only)
 {
     mc_config_t *mc_config;
     struct stat st;
@@ -128,8 +128,13 @@ mc_config_init (const gchar * ini_path)
         vpath = vfs_path_from_str (ini_path);
         if (mc_stat (vpath, &st) == 0 && st.st_size != 0)
         {
+            GKeyFileFlags flags = G_KEY_FILE_NONE;
+
+            if (!read_only)
+                flags |= G_KEY_FILE_KEEP_COMMENTS;
+
             /* file exists and not empty */
-            g_key_file_load_from_file (mc_config->handle, ini_path, G_KEY_FILE_KEEP_COMMENTS, NULL);
+            g_key_file_load_from_file (mc_config->handle, ini_path, flags, NULL);
         }
         vfs_path_free (vpath);
     }
@@ -207,7 +212,8 @@ mc_config_del_group (mc_config_t * mc_config, const char *group)
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
 gboolean
-mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean remove_empty)
+mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean read_only,
+                     gboolean remove_empty)
 {
     mc_config_t *tmp_config;
     gchar **groups, **curr_grp;
@@ -217,7 +223,7 @@ mc_config_read_file (mc_config_t * mc_config, const gchar * ini_path, gboolean r
     if (mc_config == NULL)
         return FALSE;
 
-    tmp_config = mc_config_init (ini_path);
+    tmp_config = mc_config_init (ini_path, read_only);
     if (tmp_config == NULL)
         return FALSE;
 

+ 3 - 1
lib/serialize.c

@@ -281,7 +281,7 @@ mc_deserialize_config (const char *data, GError ** error)
 {
     char *current_group = NULL, *current_param = NULL, *current_value = NULL;
     size_t current_position = 0;
-    mc_config_t *ret_data = mc_config_init (NULL);
+    mc_config_t *ret_data;
     enum automat_status
     {
         WAIT_GROUP,
@@ -289,6 +289,8 @@ mc_deserialize_config (const char *data, GError ** error)
         WAIT_VALUE
     } current_status = WAIT_GROUP;
 
+    ret_data = mc_config_init (NULL, FALSE);
+
     while (data != NULL)
     {
         if ((current_status == WAIT_GROUP) && (*data == 'p') && (current_group != NULL))

+ 4 - 4
lib/skin/ini-file.c

@@ -51,7 +51,7 @@ mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir
     file_name = g_build_filename (base_dir, MC_SKINS_SUBDIR, mc_skin->name, NULL);
     if (exist_file (file_name))
     {
-        mc_skin->config = mc_config_init (file_name);
+        mc_skin->config = mc_config_init (file_name, TRUE);
         g_free (file_name);
         return (mc_skin->config != NULL);
     }
@@ -63,7 +63,7 @@ mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir
 
     if (exist_file (file_name))
     {
-        mc_skin->config = mc_config_init (file_name);
+        mc_skin->config = mc_config_init (file_name, TRUE);
         g_free (file_name);
         return (mc_skin->config != NULL);
     }
@@ -89,7 +89,7 @@ mc_skin_ini_file_load (mc_skin_t * mc_skin)
         g_free (file_name);
         if (!g_path_is_absolute (mc_skin->name))
             return FALSE;
-        mc_skin->config = mc_config_init (mc_skin->name);
+        mc_skin->config = mc_config_init (mc_skin->name, TRUE);
         return (mc_skin->config != NULL);
     }
     g_free (file_name);
@@ -127,7 +127,7 @@ mc_skin_ini_file_parse (mc_skin_t * mc_skin)
 void
 mc_skin_set_hardcoded_skin (mc_skin_t * mc_skin)
 {
-    mc_skin->config = mc_config_init (NULL);
+    mc_skin->config = mc_config_init (NULL, TRUE);
 
     mc_config_set_string (mc_skin->config, "skin", "description", "hardcoded skin");
 

+ 6 - 2
lib/vfs/path.c

@@ -1053,7 +1053,7 @@ vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element)
 char *
 vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
 {
-    mc_config_t *cpath = mc_config_init (NULL);
+    mc_config_t *cpath;
     ssize_t element_index;
     char *ret_value;
 
@@ -1063,6 +1063,9 @@ vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
         return NULL;
 
     }
+
+    cpath = mc_config_init (NULL, FALSE);
+
     for (element_index = 0; element_index < vfs_path_elements_count (vpath); element_index++)
     {
         char *groupname;
@@ -1106,10 +1109,11 @@ vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
 vfs_path_t *
 vfs_path_deserialize (const char *data, GError ** error)
 {
-    mc_config_t *cpath = mc_deserialize_config (data, error);
+    mc_config_t *cpath;
     size_t element_index = 0;
     vfs_path_t *vpath;
 
+    cpath = mc_deserialize_config (data, error);
     if (cpath == NULL)
         return NULL;
 

+ 2 - 2
lib/widget/dialog.c

@@ -165,7 +165,7 @@ dlg_read_history (Dlg_head * h)
         return;
 
     profile = mc_config_get_full_path (MC_HISTORY_FILE);
-    event_data.cfg = mc_config_init (profile);
+    event_data.cfg = mc_config_init (profile, TRUE);
     event_data.receiver = NULL;
 
     /* create all histories in dialog */
@@ -1335,7 +1335,7 @@ dlg_save_history (Dlg_head * h)
     {
         ev_history_load_save_t event_data;
 
-        event_data.cfg = mc_config_init (profile);
+        event_data.cfg = mc_config_init (profile, FALSE);
         event_data.receiver = NULL;
 
         /* get all histories in dialog */

+ 1 - 1
lib/widget/history.c

@@ -151,7 +151,7 @@ history_get (const char *input_name)
         return NULL;
 
     profile = mc_config_get_full_path (MC_HISTORY_FILE);
-    cfg = mc_config_init (profile);
+    cfg = mc_config_init (profile, TRUE);
 
     hist = history_load (cfg, input_name);
 

+ 3 - 3
src/editor/editcmd.c

@@ -1416,7 +1416,7 @@ edit_delete_macro (WEdit * edit, int hotkey)
     }
 
     macros_fname = mc_config_get_full_path (MC_MACRO_FILE);
-    macros_config = mc_config_init (macros_fname);
+    macros_config = mc_config_init (macros_fname, FALSE);
     g_free (macros_fname);
 
     if (macros_config == NULL)
@@ -1835,7 +1835,7 @@ edit_store_macro_cmd (WEdit * edit)
     edit_delete_macro (edit, hotkey);
 
     macros_fname = mc_config_get_full_path (MC_MACRO_FILE);
-    macros_config = mc_config_init (macros_fname);
+    macros_config = mc_config_init (macros_fname, FALSE);
     g_free (macros_fname);
 
     if (macros_config == NULL)
@@ -1939,7 +1939,7 @@ edit_load_macro_cmd (WEdit * edit)
     (void) edit;
 
     macros_fname = mc_config_get_full_path (MC_MACRO_FILE);
-    macros_config = mc_config_init (macros_fname);
+    macros_config = mc_config_init (macros_fname, TRUE);
     g_free (macros_fname);
 
     if (macros_config == NULL)

+ 1 - 1
src/filemanager/treestore.c

@@ -565,7 +565,7 @@ process_special_dirs (GList ** special_dirs, char *file)
     mc_config_t *cfg;
     gsize buffers_len;
 
-    cfg = mc_config_init (file);
+    cfg = mc_config_init (file, TRUE);
     if (cfg == NULL)
         return;
 

Некоторые файлы не были показаны из-за большого количества измененных файлов