From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 4/8] mv: remove an "if" that's always true
Date: Sun, 10 Aug 2014 09:29:32 +0700 [thread overview]
Message-ID: <1407637776-19794-5-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1407637776-19794-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 524f4e5..0732355 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -175,22 +175,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
next prev parent reply other threads:[~2014-08-10 2:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-10 2:29 [PATCH v2 0/8] builtin/mv.c cleanup Nguyễn Thái Ngọc Duy
2014-08-10 2:29 ` [PATCH v2 1/8] mv: mark strings for translations Nguyễn Thái Ngọc Duy
2014-08-10 2:29 ` [PATCH v2 2/8] mv: flatten error handling code block Nguyễn Thái Ngọc Duy
2014-08-10 2:29 ` [PATCH v2 3/8] mv: split submodule move preparation code out Nguyễn Thái Ngọc Duy
2014-08-10 2:29 ` Nguyễn Thái Ngọc Duy [this message]
2014-08-10 2:29 ` [PATCH v2 5/8] mv: move index search " Nguyễn Thái Ngọc Duy
2014-08-10 2:29 ` [PATCH v2 6/8] mv: unindent one level for directory move code Nguyễn Thái Ngọc Duy
2014-08-11 18:47 ` Junio C Hamano
2014-08-12 14:57 ` Duy Nguyen
2014-08-12 17:56 ` Junio C Hamano
2014-08-10 2:29 ` [PATCH v2 7/8] mv: combine two if(s) Nguyễn Thái Ngọc Duy
2014-08-10 2:29 ` [PATCH v2 8/8] mv: no SP between function name and the first opening parenthese Nguyễn Thái Ngọc Duy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1407637776-19794-5-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).