diff options
author | Rohit Mani <rohit.mani@outlook.com> | 2014-03-08 07:48:31 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-03-10 16:35:30 +0100 |
commit | 2c5495f7b60d6ddcd6a411b48d2f6dbc4a24717a (patch) | |
tree | 9900454e2b547e2fee8e9e67b39ced68ea0c650e /match-trees.c | |
parent | Git 1.9.0 (diff) | |
download | git-2c5495f7b60d6ddcd6a411b48d2f6dbc4a24717a.tar.xz git-2c5495f7b60d6ddcd6a411b48d2f6dbc4a24717a.zip |
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>
Diffstat (limited to 'match-trees.c')
-rw-r--r-- | match-trees.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/match-trees.c b/match-trees.c index 7873cdec58..e80b4af354 100644 --- a/match-trees.c +++ b/match-trees.c @@ -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; |