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:

committed by
Junio C Hamano

parent
5f95c9f850
commit
2c5495f7b6
7
ws.c
7
ws.c
@ -33,11 +33,8 @@ unsigned parse_whitespace_rule(const char *string)
|
||||
int negated = 0;
|
||||
|
||||
string = string + strspn(string, ", \t\n\r");
|
||||
ep = strchr(string, ',');
|
||||
if (!ep)
|
||||
len = strlen(string);
|
||||
else
|
||||
len = ep - string;
|
||||
ep = strchrnul(string, ',');
|
||||
len = ep - string;
|
||||
|
||||
if (*string == '-') {
|
||||
negated = 1;
|
||||
|
Reference in New Issue
Block a user