summaryrefslogtreecommitdiff
path: root/match-trees.c
diff options
context:
space:
mode:
authorRohit Mani <rohit.mani@outlook.com>2014-03-07 22:48:31 -0800
committerJunio C Hamano <gitster@pobox.com>2014-03-10 08:35:30 -0700
commit2c5495f7b60d6ddcd6a411b48d2f6dbc4a24717a (patch)
tree9900454e2b547e2fee8e9e67b39ced68ea0c650e /match-trees.c
parent5f95c9f850b19b368c43ae399cc831b17a26a5ac (diff)
downloadgit-2c5495f7b60d6ddcd6a411b48d2f6dbc4a24717a.tar.gz
use strchrnul() in place of strchr() and strlen()rm/strchrnul-not-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.c11
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;