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
@ -182,13 +182,10 @@ static int splice_tree(const unsigned char *hash1,
|
||||
enum object_type type;
|
||||
int status;
|
||||
|
||||
subpath = strchr(prefix, '/');
|
||||
if (!subpath)
|
||||
toplen = strlen(prefix);
|
||||
else {
|
||||
toplen = subpath - prefix;
|
||||
subpath = strchrnul(prefix, '/');
|
||||
toplen = subpath - prefix;
|
||||
if (*subpath)
|
||||
subpath++;
|
||||
}
|
||||
|
||||
buf = read_sha1_file(hash1, &type, &sz);
|
||||
if (!buf)
|
||||
@ -215,7 +212,7 @@ static int splice_tree(const unsigned char *hash1,
|
||||
if (!rewrite_here)
|
||||
die("entry %.*s not found in tree %s",
|
||||
toplen, prefix, sha1_to_hex(hash1));
|
||||
if (subpath) {
|
||||
if (*subpath) {
|
||||
status = splice_tree(rewrite_here, subpath, hash2, subtree);
|
||||
if (status)
|
||||
return status;
|
||||
|
Reference in New Issue
Block a user