From df256dbaf6521263108958666cda9ac4c3b15608 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Thu, 18 Jun 2009 14:51:05 +0300 Subject: [PATCH] Ticket #415 (trivial optimization in src/file.c::panel_operate()) This patch contains the following trivial optimizations: * merged two identical "dest_dir_ = g_strdup (dest_dir)" ops. * simplified check for trailing '/' (no need to strcmp 1-char string). * since g_free (NULL) is safe, merged two separate "if empty string then bail out" code paths. * fixed wording in a comment. Signed-off-by: Slava Zanko --- src/file.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/file.c b/src/file.c index 3a62ae038..b6056bea7 100644 --- a/src/file.c +++ b/src/file.c @@ -1804,19 +1804,18 @@ panel_operate (void *source_panel, FileOperation operation, else dest_dir = panel->cwd; /* - * Add trailing backslash only when do non-locally ops. + * Add trailing backslash only when do non-local ops. * It saves user from occasional file renames (when destination * dir is deleted) */ - if (force_single) + if (!force_single + && dest_dir[0] + && dest_dir[strlen(dest_dir)-1] != PATH_SEP) { + /* add trailing separator */ + dest_dir_ = g_strconcat (dest_dir, PATH_SEP_STR, (char*)0); + } else { /* just copy */ dest_dir_ = g_strdup (dest_dir); - else - /* add trailing separator */ - if (*dest_dir && strcmp(&dest_dir[strlen(dest_dir)-1], PATH_SEP_STR)) { - dest_dir_ = g_strconcat (dest_dir, PATH_SEP_STR, (char*)0); - } else { - dest_dir_ = g_strdup (dest_dir); } if (!dest_dir_) { file_op_context_destroy (ctx); @@ -1828,11 +1827,7 @@ panel_operate (void *source_panel, FileOperation operation, single_entry, &do_bg); g_free(dest_dir_); - if (!dest) { - file_op_context_destroy (ctx); - return 0; - } - if (!*dest) { + if (!dest || !dest[0]) { file_op_context_destroy (ctx); g_free (dest); return 0;