From 20ab79ba006eeff49b61635cd5ce7efae7c01151 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 17 Sep 2013 12:59:51 +0400 Subject: [PATCH] Use vfs_translate_path() to avoid extra string duplication. Signed-off-by: Andrew Borodin --- src/subshell.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/subshell.c b/src/subshell.c index b36fbbcca..aaff5dbfe 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -924,8 +924,6 @@ init_subshell (void) int invoke_subshell (const char *command, int how, vfs_path_t ** new_dir_vpath) { - char *pcwd; - /* Make the MC terminal transparent */ tcsetattr (STDOUT_FILENO, TCSANOW, &raw_mode); @@ -957,11 +955,14 @@ invoke_subshell (const char *command, int how, vfs_path_t ** new_dir_vpath) feed_subshell (how, FALSE); - pcwd = vfs_translate_path_n (vfs_path_as_str (current_panel->cwd_vpath)); + if (new_dir_vpath != NULL && subshell_alive) + { + const char *pcwd; - if (new_dir_vpath != NULL && subshell_alive && strcmp (subshell_cwd, pcwd)) - *new_dir_vpath = vfs_path_from_str (subshell_cwd); /* Make MC change to the subshell's CWD */ - g_free (pcwd); + pcwd = vfs_translate_path (vfs_path_as_str (current_panel->cwd_vpath)); + if (strcmp (subshell_cwd, pcwd) != 0) + *new_dir_vpath = vfs_path_from_str (subshell_cwd); /* Make MC change to the subshell's CWD */ + } /* Restart the subshell if it has died by SIGHUP, SIGQUIT, etc. */ while (!subshell_alive && quit == 0 && mc_global.tty.use_subshell) @@ -1175,9 +1176,9 @@ do_subshell_chdir (const vfs_path_t * vpath, gboolean update_prompt) if (vpath != NULL) { - char *translate; + const char *translate; - translate = vfs_translate_path_n (vfs_path_as_str (vpath)); + translate = vfs_translate_path (vfs_path_as_str (vpath)); if (translate != NULL) { GString *temp; @@ -1185,8 +1186,6 @@ do_subshell_chdir (const vfs_path_t * vpath, gboolean update_prompt) temp = subshell_name_quote (translate); write_all (mc_global.tty.subshell_pty, temp->str, temp->len); g_string_free (temp, TRUE); - - g_free (translate); } else {