[PATCH] trivial optimization in file.c::panel_operate()



Hi Slava,

I noticed an incorrectly indented if() in file.c::panel_operate().
Took a better look, and found out it can be tweaked in several ways.

This patch is the result.
It 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.

Slava, is it ok to send patches in attachments?

Do you want kernel-style "Signed-off-by" lines in patch submissions?
--
vda
diff -d -urpN mc.1/src/file.c mc.2/src/file.c
--- mc.1/src/file.c	2009-06-16 16:57:06.000000000 +0200
+++ mc.2/src/file.c	2009-06-17 14:58:30.000000000 +0200
@@ -1806,19 +1806,18 @@ panel_operate (void *source_panel, FileO
 	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)
-	    /* just copy */
-	    dest_dir_ = g_strdup (dest_dir);
-	else
+	if (!force_single
+	 && dest_dir[0]
+	 && dest_dir[strlen(dest_dir)-1] != PATH_SEP) {
 	    /* 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);
+	    dest_dir_ = g_strconcat (dest_dir, PATH_SEP_STR, (char*)0);
 	} else {
-		dest_dir_ = g_strdup (dest_dir);
+	    /* just copy */
+	    dest_dir_ = g_strdup (dest_dir);
 	}
 	if (!dest_dir_) {
 	    file_op_context_destroy (ctx);
@@ -1830,11 +1829,7 @@ panel_operate (void *source_panel, FileO
 			      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;


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