use strchrnul() in place of strchr() and strlen()

Avoid scanning strings twice, once with strchr() and then with
strlen(), by using strchrnul().

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Rohit Mani <rohit.mani@outlook.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Rohit Mani
2014-03-07 22:48:31 -08:00
committed by Junio C Hamano
parent 5f95c9f850
commit 2c5495f7b6
9 changed files with 34 additions and 59 deletions

9
diff.c
View File

@ -3365,14 +3365,11 @@ static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *va
if (c != '-')
return 0;
arg++;
eq = strchr(arg, '=');
if (eq)
len = eq - arg;
else
len = strlen(arg);
eq = strchrnul(arg, '=');
len = eq - arg;
if (!len || strncmp(arg, arg_long, len))
return 0;
if (eq) {
if (*eq) {
int n;
char *end;
if (!isdigit(*++eq))