Skip to content

Commit 42de4b1

Browse files
pcloudsgitster
authored andcommitted
mv: remove an "if" that's always true
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3af05a6 commit 42de4b1

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

builtin/mv.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,22 +176,14 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
176176
if (last - first < 1)
177177
bad = _("source directory is empty");
178178
else {
179-
int j, dst_len;
179+
int j, dst_len, n;
180180

181-
if (last - first > 0) {
182-
source = xrealloc(source,
183-
(argc + last - first)
184-
* sizeof(char *));
185-
destination = xrealloc(destination,
186-
(argc + last - first)
187-
* sizeof(char *));
188-
modes = xrealloc(modes,
189-
(argc + last - first)
190-
* sizeof(enum update_mode));
191-
submodule_gitfile = xrealloc(submodule_gitfile,
192-
(argc + last - first)
193-
* sizeof(char *));
194-
}
181+
n = argc + last - first;
182+
source = xrealloc(source, n * sizeof(char *));
183+
destination = xrealloc(destination, n * sizeof(char *));
184+
modes = xrealloc(modes, n * sizeof(enum update_mode));
185+
submodule_gitfile =
186+
xrealloc(submodule_gitfile, n * sizeof(char *));
195187

196188
dst = add_slash(dst);
197189
dst_len = strlen(dst);

0 commit comments

Comments
 (0)