prefix_filename: drop length parameter

This function takes the prefix as a ptr/len pair, but in
every caller the length is exactly strlen(ptr). Let's
simplify the interface and just take the string. This saves
callers specifying it (and in some cases handling a NULL
prefix).

In a handful of cases we had the length already without
calling strlen, so this is technically slower. But it's not
likely to matter (after all, if the prefix is non-empty
we'll allocate and copy it into a buffer anyway).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King
2017-03-20 21:22:28 -04:00
committed by Junio C Hamano
parent 598019769c
commit 116fb64e43
15 changed files with 23 additions and 35 deletions

4
diff.c
View File

@ -4023,7 +4023,7 @@ int diff_opt_parse(struct diff_options *options,
else if (!strcmp(arg, "--pickaxe-regex"))
options->pickaxe_opts |= DIFF_PICKAXE_REGEX;
else if ((argcount = short_opt('O', av, &optarg))) {
const char *path = prefix_filename(prefix, strlen(prefix), optarg);
const char *path = prefix_filename(prefix, optarg);
options->orderfile = xstrdup(path);
return argcount;
}
@ -4071,7 +4071,7 @@ int diff_opt_parse(struct diff_options *options,
else if (!strcmp(arg, "--no-function-context"))
DIFF_OPT_CLR(options, FUNCCONTEXT);
else if ((argcount = parse_long_opt("output", av, &optarg))) {
const char *path = prefix_filename(prefix, strlen(prefix), optarg);
const char *path = prefix_filename(prefix, optarg);
options->file = fopen(path, "w");
if (!options->file)
die_errno("Could not open '%s'", path);