git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 5/8] mv: remove an "if" that's always true

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Aug 8, 2014, 13:10 UTC
Message-ID
<1407503462-32632-6-git-send-email-pclouds@gmail.com>
In-Reply-To
<1407503462-32632-1-git-send-email-pclouds@gmail.com>

This is inside an "else" block of "if (last - first < 1)", so we know that "last - first >= 1" when we come here. No need to check "last - first > 0".

While at there, save "argc + last - first" to a variable to shorten the statements a bit.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/mv.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)
diff --git a/builtin/mv.c b/builtin/mv.c
index e192f2d..a45226e 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -179,22 +179,14 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 				if (last - first < 1)
 					bad = _("source directory is empty");
 				else {
-					int j, dst_len;
+					int j, dst_len, n;
 
-					if (last - first > 0) {
-						source = xrealloc(source,
-								(argc + last - first)
-								* sizeof(char *));
-						destination = xrealloc(destination,
-								(argc + last - first)
-								* sizeof(char *));
-						modes = xrealloc(modes,
-								(argc + last - first)
-								* sizeof(enum update_mode));
-						submodule_gitfile = xrealloc(submodule_gitfile,
-								(argc + last - first)
-								* sizeof(char *));
-					}
+					n = argc + last - first;
+					source = xrealloc(source, n * sizeof(char *));
+					destination = xrealloc(destination, n * sizeof(char *));
+					modes = xrealloc(modes, n * sizeof(enum update_mode));
+					submodule_gitfile =
+						xrealloc(submodule_gitfile, n * sizeof(char *));
 
 					dst = add_slash(dst);
 					dst_len = strlen(dst);
-- 
2.1.0.rc0.78.gc0d8480
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 8 of 11 in “builtin/mv.c cleanup”
  1. 0/8 builtin/mv.c cleanupNguyễn Thái Ngọc Duy, Aug 8, 2014
  2. 1/8 mv: mark strings for translationsNguyễn Thái Ngọc Duy, Aug 8, 2014
  3. 2/8 mv: no "Huh?" to the userNguyễn Thái Ngọc Duy, Aug 8, 2014
  4. Junio C HamanoAug 8, 2014
  5. 3/8 mv: flatten error handling code blockNguyễn Thái Ngọc Duy, Aug 8, 2014
  6. Junio C HamanoAug 8, 2014
  7. 4/8 mv: split submodule move preparation code outNguyễn Thái Ngọc Duy, Aug 8, 2014
  8. 5/8 mv: remove an "if" that's always trueNguyễn Thái Ngọc Duy, Aug 8, 2014
  9. 6/8 mv: move index search code outNguyễn Thái Ngọc Duy, Aug 8, 2014
  10. 7/8 mv: unindent one level for directory move codeNguyễn Thái Ngọc Duy, Aug 8, 2014
  11. 8/8 mv: combine two if(s)Nguyễn Thái Ngọc Duy, Aug 8, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.