diff options
author | Rohit Mani <rohit.mani@outlook.com> | 2014-03-07 22:48:31 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-03-10 08:35:30 -0700 |
commit | 2c5495f7b60d6ddcd6a411b48d2f6dbc4a24717a (patch) | |
tree | 9900454e2b547e2fee8e9e67b39ced68ea0c650e /cache-tree.c | |
parent | 5f95c9f850b19b368c43ae399cc831b17a26a5ac (diff) | |
download | git-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 'cache-tree.c')
-rw-r--r-- | cache-tree.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/cache-tree.c b/cache-tree.c index 0bbec43216..2130f32e26 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -121,11 +121,11 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path) if (!it) return; - slash = strchr(path, '/'); + slash = strchrnul(path, '/'); + namelen = slash - path; it->entry_count = -1; - if (!slash) { + if (!*slash) { int pos; - namelen = strlen(path); pos = subtree_pos(it, path, namelen); if (0 <= pos) { cache_tree_free(&it->down[pos]->cache_tree); @@ -143,7 +143,6 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path) } return; } - namelen = slash - path; down = find_subtree(it, path, namelen, 0); if (down) cache_tree_invalidate_path(down->cache_tree, slash + 1); @@ -554,9 +553,7 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat const char *slash; struct cache_tree_sub *sub; - slash = strchr(path, '/'); - if (!slash) - slash = path + strlen(path); + slash = strchrnul(path, '/'); /* between path and slash is the name of the * subtree to look for. */ @@ -564,10 +561,10 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat if (!sub) return NULL; it = sub->cache_tree; - if (slash) + if (*slash) while (*slash && *slash == '/') slash++; - if (!slash || !*slash) + if (!*slash) return it; /* prefix ended with slashes */ path = slash; } |